How to Get Mac Address in Javascript?
javascript get system mac address
<?php
// PHP code to get the MAC address of Client
$MAC = exec('getmac');
// Storing 'getmac' value in $MAC
$MAC = strtok($MAC, ' ');
// Updating $MAC value using strtok function,
// strtok is used to split the string into tokens
// split character of strtok is defined as a space
// because getmac returns transport name after
// MAC address
echo "MAC address of client is: $MAC";
?>
Use the ActiveX Object to Get MAC Address in JavaScript
To enable the ActiveX object, we will go to Tools and select Internet Options. Then on the Security tab, we will click on Custom Level.
We will go down until we see Initialize and the script ActiveX controls not marked as safe. We will enable it, then click Ok.
<script type="text/javascript">
var macAddress = "";
var computerName = "";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
macAddress = s.MACAddress;
computerName = s.DNSHostName;
}
</script>
<script type="text/javascript">
<input type="text" id="txtMACAdress" />
<input type="text" id="txtComputerName" />
<script type="text/javascript">
document.getElementById("txtMACAdress").value = unescape(macAddress);
document.getElementById("txtComputerName").value = unescape(computerName);
</script>