如果要想获得远程的地址,需要用sendarp这个函数来实现。具体的代码如下:
[dllimport("iphlpapi.dll")]
private static unsafe extern int sendarp(int32 dest,int32 host,ref intptr mac,ref intptr length);
[dllimport("ws2_32.dll")]
private static extern int32 inet_addr(string ip);
int32 ldest= inet_addr("157.60.68.163");//目的地的ip
int32 lhost= inet_addr("157.60.68.33");//本地的ip
try
{
byte[] macinfo=new byte[6];
int32 length=6;
intptr mac=new intptr(macinfo[0]);
intptr len=new intptr(6);
int ii=sendarp(ldest,lhost, ref mac, ref len);
console.writeline("mac add:"+mac);
console.writeline("length:"+len);
}
catch(exception err)
{
console.writeline(err);
}
新闻热点
疑难解答