获取远程网卡MAC地址(C#)

[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 .Net_addr(string ip);

static private Int64 getRemoteMAC(string localIP, string remoteIP)
{
Int32 ldest= .Net_addr(remoteIP); //目的地的ip
Int32 lhost= .Net_addr(localIP); //本地服务器的ip

try
{
Int64 macinfo = new Int64();
Int32 len = 6;
int res = SendARP(ldest,0, ref macinfo, ref len);
return macinfo;
}
catch(Exception err)
{
Console.WriteLine("Error:{0}",err.Message);
}
return 0;
}

如何获得System.Management?
引用下 System.Management 这个.Net组件就行了.
提示: 类型或命名空间名称“Management”在类或命名空间“System”中不存在(是否缺少程序集引用?)——怎么回事?
“添加引用”-->“.Net组件”-->找到System.Management.dll组件。按引用即可拉。


posted on 2007-03-21 16:18  石川  阅读(292)  评论(0编辑  收藏  举报