1 /// <summary>
2 /// 获取电脑 MAC(物理) 地址
3 /// </summary>
4 /// <returns></returns>
5 public string GetMACIp()
6 {
7 //本地计算机网络连接信息
8 IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
9 //获取本机所有网络连接
10 NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
11
12 //获取本机电脑名
13 var HostName = computerProperties.HostName;
14 //获取域名
15 var DomainName = computerProperties.DomainName;
16
17 if (nics == null || nics.Length < 1)
18 {
19 return "";
20 }
21
22 var MACIp = "";
23 foreach (NetworkInterface adapter in nics)
24 {
25 var adapterName = adapter.Name;
26
27 var adapterDescription = adapter.Description;
28 var NetworkInterfaceType = adapter.NetworkInterfaceType;
29 if (adapterName == "本地连接")
30 {
31 PhysicalAddress address = adapter.GetPhysicalAddress();
32 byte[] bytes = address.GetAddressBytes();
33
34 for (int i = 0; i < bytes.Length; i++)
35 {
36 MACIp += bytes[i].ToString("X2");
37
38 if (i != bytes.Length - 1)
39 {
40 MACIp += "-";
41 }
42 }
43 }
44 }
45
46 return MACIp;
47 }