当前位置:首页 > 网络编程 > 软件语言 > .NET > 用C#编写获取远程IP,MAC的方法

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

点击次数:89 次 发布日期:2008-11-06 08:08:06 作者:源代码网
源代码网推荐
广告载入中
如果要想获得远程的地址,需要用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);
源代码网推荐}
源代码网推荐

源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华