无法在 Windows 8 上使用 Javascript ActiveXObject 检测客户端 mac 地址

Cannot detect client mac address using Javascript ActiveXObject On Windows 8

本文关键字:ActiveXObject Javascript 检测 客户端 地址 mac Windows      更新时间:2023-09-26

我正在尝试在Windows 8上使用JavaScript ActiveXObject获取客户端MAC地址,但它不起作用。

实际上它在Windows 7上运行良好。

这是我的代码:

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>';
}

在Windows 7中,它给出以下结果:

请注意,ID [00000007] 检测到网卡 MACAddress 成功,这是我正在使用的。

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 

但是在Windows 8上,它给了我以下结果

注意:我的网卡不在列表中?我不知道为什么?

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

有什么想法吗?

您的代码跳过查询的第一个结果(即第一个网络接口,ID 通常为 00000000),这可能恰好是 Windows 8 盒子上唯一具有 MAC 地址的结果。

e.moveNext()移动到循环的末尾,看看它现在是否显示:

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>';