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

标签 javascript c# asp.net

我尝试在 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

有什么想法吗?

最佳答案

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

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

关于javascript - 无法在 Windows 8 上使用 Javascript ActiveXObject 检测客户端 MAC 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626168/

相关文章:

javascript - React - 重构类组件以将部件移动到功能组件

c# - 如何修复 "The provider is not compatible with the version of Oracle client"?

javascript - 如何将 anchor 标记添加到字符串 Prop ?

javascript - 在两个同级 React.js 组件之间传递数据

javascript - 在 JavaScript 中通过字符串调用函数

c# - "SelectedIndexChanged"在 ListBox 中的 "Items.Clear()"之后不触发

C#:根据 bool 值选择运算符(一行)

c# - 使用 Entity Framework 在数据库中创建表

asp.net - 如何将 Silverlight 项目添加到 ASP.NET 项目?

asp.net - 如果在客户端机器上禁用 cookie, session 存储在哪里? session 中实际存储了什么?