CSDN博客

img ncowboy

获取对方的mac地址

发表于2004/9/28 16:26:00  2521人阅读

分类: .net

using System;
using System.Runtime.InteropServices;


class Program
{
[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 inet_addr(string ip);

static private Int64 getRemoteMAC(string remoteIP)
{
Int32 ldest= inet_addr(remoteIP); //目的地的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;
}

static void Main()
{
  Console.Write("I P:");
  Int64 mac=getRemoteMAC(Console.ReadLine());
  Console.WriteLine("MAC:{0}",Convert.ToString(mac,16));
}
}

阅读全文
0 0

相关文章推荐

img
取 消
img