简体   繁体   中英

Cannot detect client mac address using Javascript ActiveXObject On Windows 8

I am trying to get client mac address using JavaScript ActiveXObject On Windows 8 but it didn't work.

actually it works fine on windows 7.

Here is My Code:

var obj = new ActiveXObject("WbemScripting.SWbemLocator");
var s = obj.ConnectServer(".");
var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator(properties);
var output;
var outputTemp = "";
var Number6MacAddress = "";
var ReturnedMACAddresesses = "";
output = '<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">';
outputTemp = '';
output = output + '<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>';
var Counter = 0;
while (!e.atEnd()) {
  e.moveNext();
  var p = e.item();
  if (!p) continue;
  output = output + '<tr bgColor="#FFFFFF">';
  output = output + '<td>' + p.Caption; +'</td>';
  output = output + '<td>' + p.MACAddress + '</td>';
  //output = output + '<td>' + p.Properties_[43].Value + '</td>';
  output = output + '</tr>';
}

In Windows 7 it gives the following result:

Notice That ID [00000007] detected Network card MACAddress Successfully and this what i am using.

 Caption MACAddress [00000001] WAN Miniport (IKEv2) null [00000002] WAN Miniport (L2TP) null [00000003] WAN Miniport (PPTP) null [00000004] WAN Miniport (PPPOE) null [00000005] WAN Miniport (IPv6) null [00000006] WAN Miniport (Network Monitor) null [00000007] Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.20) 50:E5:49:FC:4D:3F [00000008] WAN Miniport (IP) null [00000009] Microsoft ISATAP Adapter null [00000010] RAS Async Adapter null [00000011] Microsoft Teredo Tunneling Adapter null [00000012] Remote NDIS based Internet Sharing Device null [00000013] Microsoft ISATAP Adapter null 

But on Windows 8 it gives me the following result

NOTICE: My Network Card is not on the list? I don't know why?

 Caption - MACAddress [00000001] - Microsoft Kernel Debug Network Adapter null [00000002] - Microsoft ISATAP Adapter null [00000003] - Microsoft Teredo Tunneling Adapter null 

any ideas?

Your code is skipping the first result of the query (that is, the first network interface, with ID 00000000 normally) which might happen to be the only one with a MAC address on your Windows 8 box.

Move the e.moveNext() to the end of the loop and see if it shows now:

var obj = new ActiveXObject("WbemScripting.SWbemLocator");
var s = obj.ConnectServer(".");
var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator(properties);
var output = '<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">';
output = output + '<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>';
while (!e.atEnd()) {
  var p = e.item();
  if (!p) continue;
  output = output + '<tr bgColor="#FFFFFF">';
  output = output + '<td>' + p.Caption; +'</td>';
  output = output + '<td>' + p.MACAddress + '</td>';
  output = output + '</tr>';
  e.moveNext();
}
output = output + '</table>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM