用C#编写获取远程IP,MAC的方法
摘要:如果要想获得远程的地址,需要用sendarp这个函数来实现。具体的代码如下:[DllImport("Iphlpapi.dll")]priva...
如果要想获得远程的地址,需要用sendarp这个函数来实现。具体的代码如下:
[DllImport("Iphlpapi.dll")]
privatestaticunsafeexternintSendARP(Int32dest,Int32host,refIntPtrmac,refIntPtrlength);
[DllImport("Ws2_32.dll")]
privatestaticexternInt32inet_addr(stringip);
Int32ldest=inet_addr("157.60.68.163");//目的地的ip
Int32lhost=inet_addr("157.60.68.33");//本地的ip
try
{
Byte[]macinfo=newByte[6];
Int32length=6;
IntPtrmac=newIntPtr(macinfo[0]);
IntPtrlen=newIntPtr(6);
intii=SendARP(ldest,lhost,refmac,reflen);
Console.WriteLine("MacAdd:"+mac);
Console.WriteLine("length:"+len);
}
catch(Exceptionerr)
{
Console.WriteLine(err);
}
【用C#编写获取远程IP,MAC的方法】相关文章:
★ C#中使用IrisSkin2.dll美化WinForm程序界面的方法
★ 用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码
上一篇:
使用C#开发Socket通讯的方法
下一篇:
C#独立域名查询代码