通过IP地址,获取MAC地址,好像只能适用于局域网

public class ClassNetGetMac
 {
  public ClassNetGetMac()
  {
  }
  [DllImport("Iphlpapi.dll")]
  private static extern int SendARP(Int32 dest,Int32 host,byte[] mac,ref Int32 length);
  [DllImport("Ws2_32.dll")]
  private static extern Int32 inet_addr(string ip);
  /// <summary>
  /// 根据ip得到网卡mac地址
  /// </summary>
  /// <param name="ip">给出的ip地址</param>
  /// <returns>对应ip的网卡mac地址</returns>
  public static string GetMACByIP(string ip)
  {
   try
   {
    byte[] aa=new byte[6];
    Int32 ldest= inet_addr(ip); //目的地的ip
    Int64 macinfo = new Int64();
    Int32 len = 6;
    int res = SendARP(ldest,0, aa, ref len);
    return BitConverter.ToString( aa, 0, 6 );;
   }
   catch(Exception err)
   {
    throw err;
   }
  }
 }
 

本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/cnming/archive/2004/12/20/222372.aspx

你可能感兴趣的:(职场,IP地址,休闲,mac地址)