如何获取客户端系统(浏览器)MAC地址。 [英] How to get client system (browser) MAC Address.

查看:2421
本文介绍了如何获取客户端系统(浏览器)MAC地址。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取客户端系统(浏览器)MAC地址。



我在www.xyx.com这样的域中启动项目后,它返回服务器MAC地址,而不是客户端系统MAC地址。

如果有人知道,请帮助我。

我尝试以下解决方案,但它只返回服务器MAC地址



解决方案1:



How to get client system (browser) MAC Address.

After I launch in my project in one domain like www.xyx.com, it returns server MAC Address, instead of Client system MAC Address.
If anybody knows, please help me.
I try the following solutions, but it returns only server MAC Address

Solution 1:

private string GetMAC()
{
   string macAddresses = "";

   foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
   {
      if (nic.OperationalStatus == OperationalStatus.Up)
      {
         macAddresses += nic.GetPhysicalAddress().ToString();
         break;
      }
   }
   return macAddresses;
}



解决方案2:




Solution 2:

public string GetMACAddress()
{
   ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
   ManagementObjectCollection moc = mc.GetInstances();
   string MACAddress = String.Empty;
   foreach (ManagementObject mo in moc)
   {
      if (MACAddress == String.Empty) // only return MAC Address from first card   
      {
         if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
      }
      mo.Dispose();
   }

   MACAddress = MACAddress.Replace(":", "");
   return MACAddress;
}

推荐答案

您无法在服务器上获取客户端MAC地址 - 它不会传输到路由器之外,它只用于初始识别设备,以便分配内部LAN / WAN IP地址。



无论何时在服务器上查询NIC数据,将获取与服务器相关的数据,而不是客户端。
You can't get the Client MAC address on the server - it isn't transferred beyond the router, and it's only used there to initially identify the equipment so that an internal LAN / WAN IP address can be assigned.

Whenever you query NIC data on the server, you will get server related data, not client.


您的代码片段用于从运行代码的接口检索数据。您可以直接获得服务器的MAC地址。

正如OriginalGriff声明的那样,只有在本地VLAN中才能获得客户端MAC,这种情况非常罕见。但你为什么需要呢?用于识别客户?它不适合。您可以使用一些客户端组件来获取它 - 但它效率非常低,即使您可以获得它,也可以更改它,因此它是不可靠的。

有更好的方法。
Your code snippets are for retrieving data from interfaces where your code is running. It is straightforward that you get server's MAC addresses.
As OriginalGriff stated you can't really get client MAC, only if it is in your local VLAN, which is quite uncommon. But why do you need that? For identifying a client? It's not suitable for that. You could use some client side components to get it - but it would be highly inefficient, and even if you could get it, it can be changed, thus it is unreliable.
There are better means for that.


这篇关于如何获取客户端系统(浏览器)MAC地址。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆