Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bluetooth mac address from local pc?

I want to get the mac address of the bluetooth device on the pc my application is running on.

I have tried the following:

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

But the output does not match with 'ipconfig /all' in commandprompt. It does not print my blueotths mac address. Any solutions?

I am ready to parse the output I get from 'ipconfig /all' but how do I get the output as a String?

like image 904
Mads Andersen Avatar asked Nov 16 '25 07:11

Mads Andersen


1 Answers

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;
}
like image 53
kartik Avatar answered Nov 18 '25 21:11

kartik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!