1。用C#调用DOS命令获取本机网卡的MAC地址
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.CreateNoWindow=true;
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.FileName="ipconfig";
p.StartInfo.Arguments="/all";
p.Start();
p.WaitForExit();
string s=p.StandardOutput.ReadToEnd();
MessageBox.Show(s.Substring(s.IndexOf("Physical Address. . . . . . . . . :")+36,17));

2。使用API,利用ARP协议,只能获得同网段计算机的MAC


     #region By ARP
获取本机的MAC的方法
获取本机的MAC的方法        [DllImport("Iphlpapi.dll")]
获取本机的MAC的方法        private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
获取本机的MAC的方法
获取本机的MAC的方法        [DllImport("Ws2_32.dll")]
获取本机的MAC的方法        private static extern Int32 inet_addr(string ip);
获取本机的MAC的方法
获取本机的MAC的方法        public static string GetMacByARP(string clientIP)
        #endregion

相关文章:

  • 2021-05-20
  • 2021-05-20
  • 2022-12-23
  • 2021-11-19
  • 2021-11-19
  • 2021-06-12
  • 2021-10-30
猜你喜欢
  • 2022-03-08
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-05-25
  • 2021-05-27
相关资源
相似解决方案