MAC地址的读取v

或是能不能直接读出来,我在CSDN的贴里找到了一个C#的代码,但是读出来的是十进制的数.

以下是我找到的那段代码:

using System;
using System;
using System.Runtime.InteropServices;

namespace test
{
 /// <summary>
 /// MACAddr 的摘要说明。
 /// </summary>
 public class MACAddr
 {
  private MACAddr()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  [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 public Int64 getRemoteMAC(string localIP, string remoteIP)
  {
   Int32 ldest= inet_addr(remoteIP); //目的地的ip
   Int32 lhost= inet_addr(localIP); //本地服务器的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;
  }
 }
}

posted on 2004-10-22 09:32  KK的Blog  阅读(916)  评论(0)    收藏  举报

导航