如何获取客户端计算机的Mac地址. [英] How to get Mac Address of Client machine.

查看:114
本文介绍了如何获取客户端计算机的Mac地址.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我,如何获取客户端计算机的Mac地址并将其存储到数据库中.


谢谢.

Can anybody help me , how to get client machine''s Mac address & store it into database.


Thanks.

推荐答案

您不能-MAC地址不在Internet上广播,并且没有浏览器界面可以访问它.
您可以通过编写ActiveX控件来通过WMI进行访问来获取它,但是-它很大,但是-它仅适用于Windows计算机,并且不适用于大多数计算机,因为它们会禁止出于安全原因无论如何都必须安装控件.
You can''t - MAC addresses are not broadcast across the internet, and there is no browser interface to access it.
You could get it by writing an ActiveX control to access it via WMI, but - and it''s a big but - it will only work on Windows machines, and it won''t work on the majority of them because they will forbid the installation of your control anyway for security reasons.


使用WMI,您可以获得一定的限制,请参阅:
http://social.msdn.microsoft.com /forums/zh-CN/netfxnetcom/thread/2b125a0e-f67d-476f-b8a0-a21c99279d5b/ [ http://social.msdn.microsoft.com/Forums/zh/netfxnetcom/thread/1344dad4-dffe-486c-bf30-1b75d21fc9ba [ C#:获取Mac地址 [ ^ ]
Using WMI, you can get this with certain limitations, refer:
http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/2b125a0e-f67d-476f-b8a0-a21c99279d5b/[^]
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/1344dad4-dffe-486c-bf30-1b75d21fc9ba[^]

Based on limitations, it''s difficult to get for remote/internet client system as it would need credentials. If by default ASPNET has permission then you might be able to extract it.

Another was could be using ActiveX, implementing in Javascript - but this would be only IE based that too would need client machine to allow activeX to run.


UPDATE:
I do see this method claiming able to get MAC address for intranet + internet: C#: Get Mac Address[^]


MAC地址是数据包的layer1属性(用于TCP/IP堆栈的Google),因此它仅在具有layer2交换的网络上可见.任何Layer3交换机或路由器都将在数据包中替换它.
如果可以在ping后用ARP -a看到它,则可以在C#代码中执行相同的操作,可以在进程中发出此命令,也可以使用以下代码:

MAC address is a layer1 attribute of the packet (google for TCP/IP stack), thus it is only visible on a network with layer2 switching. Any layer3 switch or router will replace it in the packet.
If you can see it with ARP -a after a ping, than you can do the same in a C# code, either issuing this command in a process, or with the following code:

public static class IPHelper
    {
        [DllImport("iphlpapi.dll", ExactSpelling=true)]
        public static extern int SendARP( int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);

        public static string getMAC(IPAddress address)
        {
            int intAddress = BitConverter.ToInt32(address.GetAddressBytes(), 0);

            byte[] macAddr = new byte[6];
            uint macAddrLen = (uint) macAddr.Length;
            if (SendARP(intAddress, 0, macAddr, ref macAddrLen) != 0)
                return "(NO ARP result)";

            string[] str = new string[(int)macAddrLen];
            for (int i = 0; i < macAddrLen; i++)
                str[i] = macAddr[i].ToString("x2");

            return string.Join(":", str);
        }
    }



L2外围的主机无法使用通用工具查询其MAC,因此,如果您无权远程读取其配置(WMI,SNMP等),或者它们是不同的哑设备,或者...没有什么比为您提供适合每个客户的解决方案了.

更新:
MAC地址不能保证唯一,可以更改.因此,它不适合用于机器识别.
如果要从计算机端进行强身份验证,则可以使用基于证书的身份验证.只有具有您颁发的证书的客户端才能通过身份验证.而且这也将确保平等.在域环境中,这真的很容易采用.



Hosts outside your L2 perimeters can not be queried for their MAC with common tools, so if you don''t have access read their configuration remotely (WMI, SNMP,...), or they are different dumb devices, or... than nothing will give you a solution working for every client.

Update:
MAC address is not guaranteed to be unique, and it can be changed. Thus it is not suitable for machine identification.
If you want strong authentication from machine side, you can use certificate based authentication. Only clients with certificates issued by you will be able to pass the authentication. And this one will also ensure the uniquality. In a domain environment this is really easy to adopt.


这篇关于如何获取客户端计算机的Mac地址.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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