發布時間:2020-11-30 15:40 作者:獨孤劍 閱讀:1164
using System; using System.Collections.Generic; using System.Management; using System.Net; namespace DemoConsole { class Program { static void Main(string[] args) { // 獲取本機網卡列表 List<string> list = GetMAC(); Console.WriteLine(string.Join(",", list.ToArray())); Console.Read(); } ///<summary> /// 通過WMI讀取系統信息里的MAC (網卡) 地址 ///</summary> ///<returns></returns> public static List<string> GetMAC() { try { List<string> macs = new List<string>(); ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if ((bool)mo["IPEnabled"]) { var mac = mo["MacAddress"].ToString(); macs.Add(mac); } } return macs; } catch { throw; } } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞