Asp.net client MAC

来源:互联网 发布:浅青绿的自定义rgb数据 编辑:程序博客网 时间:2024/05/22 07:41

[DllImport("Iphlpapi.dll")] private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length); [DllImport("Ws2_32.dll")] private static extern Int32 inet_addr(string ip); public string GetClientMac(string IP) { string MacAddress = "";//mac地址 例如:"00-13-D4-D5-2F-20" try { Int32 ClientIP = inet_addr(IP); //目的地的ip(客户端Ip的Int32形式:"67152064") Int64 MacInfo = new Int64();//存储mac地址的Int64形式:"35389822997248" Int32 Length = 6; int res = SendARP(ClientIP, 0, ref MacInfo, ref Length); string mac_src = MacInfo.ToString("X");//存储mac地址的16进制形式:"202fd5d41300" while (mac_src.Length < 12) { mac_src = mac_src.Insert(0, "0");//不足12为则用0来填充 } //把Int32形式的IP转换为"00-13-D4-D5-2F-20"形式的mac地址 for (int i = 0; i < 11; i++) { if (0 == (i % 2)) { if (i == 10) { MacAddress = mac_dest.Insert(0, mac_src.Substring(i, 2)); } else { MacAddress = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2)); } } } } catch (Exception err) { throw err; } return mac_dest; }

 

copy link:http://topic.csdn.net/u/20080804/10/1035886f-75f9-4a82-9d6e-f1127844dd05.html

原创粉丝点击