天天看點

winform擷取本機mac位址

private string GetMacAddress()
        {
            System.Net.IPHostEntry myEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            //string ipAddress = myEntry.AddressList[0].ToString();

            List<string> macList = new List<string>();

            foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    macList.Add(nic.GetPhysicalAddress().ToString());
                }
            }
            if (macList != null && macList.Count > 0)
            {
                //button1.Text = macList[0];
                //Console.WriteLine(macList[0]);
            }
            return macList[0];
        }
           

繼續閱讀