当前位置: 移动技术网 > IT编程>开发语言>c# > 用C#编写获取远程IP,MAC的方法

用C#编写获取远程IP,MAC的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
如果要想获得远程的地址,需要用sendarp这个函数来实现。具体的代码如下:  [dllimport("iphlpapi.dll")]  private
如果要想获得远程的地址,需要用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); 

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网