zoukankan      html  css  js  c++  java
  • 获取远程主机的MAC(转贴)

    using System.Runtime.InteropServices;

      [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 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;
      }
    ---------------------------------

  • 相关阅读:
    第一次结对作业
    第二次编程作业
    第一次编程作业
    第一次博客作业*
    个人总结
    第三次个人作业
    第二次结对作业
    第一次结对作业
    第二次个人编程作业
    第一次个人编程作业
  • 原文地址:https://www.cnblogs.com/stevenxiao/p/274745.html
Copyright © 2011-2022 走看看