gpt4 book ai didi

c# - 如何从本地电脑获取蓝牙mac地址?

转载 作者:行者123 更新时间:2023-11-30 21:23:19 25 4
gpt4 key购买 nike

我想获取运行我的应用程序的 pc 上蓝牙设备的 mac 地址。

我尝试了以下方法:

private void GetMacAddress()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
Console.WriteLine(macAddresses);
}
}
}

但输出与命令提示符中的“ipconfig/all”不匹配。它不会打印我的 blueotths mac 地址。有什么解决办法吗?

我已准备好解析从“ipconfig/all”获得的输出,但我如何获得字符串形式的输出?

最佳答案

public static PhysicalAddress GetBTMacAddress()  {

foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) {

// Only consider Bluetooth network interfaces
if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx &&
nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211){

return nic.GetPhysicalAddress();
}
}
return null;
}

关于c# - 如何从本地电脑获取蓝牙mac地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1819971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com