日期:2014-05-18 浏览次数:20456 次
[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; }
------解决方案--------------------
都不太能
现在的状况下,你是不可能在页面上运行
wscript ,更不可能调用wmi
------解决方案--------------------
至于arp的那个,完全是局域网用的,广域网上一点用都没有
------解决方案--------------------
如果发送ARP包来查询mac地址的话,基本上会被防火墙屏蔽