c#中使用ARP获取mac地址
来源:互联网 发布:linux创建命令 编辑:程序博客网 时间:2024/05/17 13:13
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Text;
[DllImport("Iphlpapi.dll")]
private static unsafe extern int SendARP(Int32 dest,Int32 host,ref Int32 mac,ref Int32 length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);
public string GetMACFromIP(string A_strIP)
{
string strRet = "Unknown";
string strIPPattern = @"^/d+/./d+/./d+/./d+$";
Regex objRex =new Regex(strIPPattern);
if(objRex.IsMatch(A_strIP) == true)
{
Int32 intDest = inet_addr(A_strIP);
Int32 [] arrMAC = new Int32[2];
Int32 intLen = 6;
int intResult = SendARP(intDest,0,ref arrMAC[0],ref intLen);
if(intResult == 0)
{
Byte [] arrbyte = new Byte[8];
arrbyte[5] = (Byte)(arrMAC[1] >> 8);
arrbyte[4] = (Byte)arrMAC[1];
arrbyte[3] = (Byte)(arrMAC[0] >> 24);
arrbyte[2] = (Byte)(arrMAC[0] >> 16);
arrbyte[1] = (Byte)(arrMAC[0] >> 8);
arrbyte[0] = (Byte)arrMAC[0];
StringBuilder strbMAC = new StringBuilder();
for(int intIndex = 0 ;intIndex < 6;intIndex ++)
{
if(intIndex > 0) strbMAC.Append("-");
strbMAC.Append(arrbyte[intIndex].ToString("X2"));
}
strRet = strbMAC.ToString();
}//end of if // end of if objRex..
return strRet;
}
- c#中使用ARP获取mac地址
- c#中使用ARP获取mac地址
- C#通过ARP获取指定IP的MAC地址
- C#通过ARP获取指定IP的MAC地址
- 获取远程MAC地址-ARP
- 通过ARP协议获取MAC地址
- C# 获取MAC地址
- c# 获取MAC地址
- 有些arp请求报文中为什么会有目的mac地址(不使用广播地址)
- 有些arp请求报文中为什么会有目的mac地址(不使用广播地址)
- C#中通过IP获取MAC地址,获取本机IP和MAC地址
- C#中通过IP获取MAC地址,获取本机IP和MAC地址
- ARP绑定MAC地址
- arp 绑定mac地址
- c# 获取机器mac地址
- C#获取网卡Mac地址
- C#获取网卡Mac地址
- C#获取网卡Mac地址
- SQL 获得系统所有数据库的所有表以及指定数据库的指定表的字段
- java基础教程-对象的传递与返回
- java基础教程-异常处理
- java基础教程-包和接口
- 浅析.Net下的多线程编程
- c#中使用ARP获取mac地址
- java基础教程-输入/输出、小应用程序和其他主题
- 详谈调用winpcap驱动写arp多功能工具(一)
- java基础教程-多线程编程
- java基础教程-网络应用
- WinPcap中Pocket.dll里的PacketGetAdapterNames这个API在C#里面的调用
- java基础教程-GUI
- MiniScript脚本语言扩展
- 在Eclipse下开发struts前期准备