10
A
回答
7
無法獲取被禁用的適配器的MAC地址:這是因爲獲取MAC地址需要查詢驅動程序,並且未加載禁用的適配器的驅動程序(source)。
但是,您可以獲取當前未連接的適配器的MAC地址。
這裏的WMI路由不好,因爲它顯示的MAC地址爲空,表示沒有連接的適配器。好消息是,NetworkInterface.GetAllNetworkInterfaces()
路線工作得很好:
// using System.Net.NetworkInformation;
var nics = NetworkInterface.GetAllNetworkInterfaces();
// pick your NIC!
var selectedNic = nics.First();
var macAddress = selectedNic.GetPhysicalAddress().ToString();
1
您可以使用WMI:
public static string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress=String.Empty;
foreach(ManagementObject mo in moc)
{
if(MACAddress==String.Empty) // only return MAC Address from first card
{
MACAddress= mo["MacAddress"].ToString() ;
}
mo.Dispose();
}
return MACAddress;
}
1
請參閱此鏈接。這裏
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx
的例子顯示所有接口的物理地址而不論其操作階段的。 HTH。
相關問題
- 1. 獲取C#中網絡適配器的原始MAC地址#
- 2. C++:獲取Vista上的網絡適配器的MAC地址?
- 3. 從網絡適配器讀取MAC地址
- 4. 僅使用MAC地址標識網絡適配器
- 5. Ping網絡並獲取mac地址
- 6. 如何從網絡上的IP地址獲取MAC地址?
- 7. 如何獲得網絡適配器的IP地址
- 8. 在WinXP上獲取C++中無線適配器的mac地址
- 9. 如何可靠地獲取計算機的板載網絡適配器的MAC地址?
- 10. 獲取本地網絡中的現場主機MAC地址
- 11. 如何獲取使用java的網絡設備的MAC地址
- 12. 獲取網絡用戶的IP地址
- 13. Arduino搜索網絡的IP地址,並獲得MAC地址
- 14. C#使用Mono獲取MAC地址(適用於Mac平臺)
- 15. 獲取MAC地址
- 16. 獲取網絡上的所有IP和MAC地址
- 17. 如何獲取WiFi網絡接口的MAC地址?
- 18. 列表網絡適配器名稱與IPv4地址
- 19. 從默認網關獲取mac地址?
- 20. 捕獲網絡適配器上/下和地址更改事件(Windows,C#)
- 21. 特定MAC地址掃描網絡 - Android
- 22. Python掃描網絡IP地址和mac
- 23. 區分VMware網絡適配器與物理網絡適配器 - 或 - 檢測虛擬網絡適配器
- 24. 使用msft_netadapter獲取網絡適配器的速度和IP
- 25. 獲取適配器帶寬和可用IP地址
- 26. 獲取多個MAC地址
- 27. 獲取MAC地址與Java
- 28. 獲取MAC地址C#
- 29. 安卓獲取Mac地址
- 30. win32 C API調用禁用網絡適配器?
你可以發佈你用在適配器啓用了代碼,然後提到在接聽電話時,適配器被禁用不工作? – 2010-06-30 05:40:44