Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get BSSID of all wifi access points?

I need to get BSSID(MAC) of all AP's. Please find below code block.

    List<WifiConfiguration> test =  wifiManager.getConfiguredNetworks();
    for(int k=0;k<test.size();k++){ 
        Log.d("acheck", "test BSSID = "+test.get(k).BSSID);         
        Log.d("acheck", "test BSSID = "+test.get(k).BSSID);    
   }

But above code block returns SSID properly but null for BSSID. I want to connect to strongest access point with user defined SSID. Is there any API method available to get best signal strength's AP with user defined SSID.(In my case there are many SSID's with single SSID with multiple AP's available.)

like image 902
Balaji Khadake Avatar asked Sep 17 '12 13:09

Balaji Khadake


People also ask

What is an BSSID number for WiFi?

The SSID (Service Set Identifier) is the name of your wireless network, also known as Network ID. This is viewable to anyone with a wireless device within reachable distance of your network. It's recommended you set up a password so not just anybody can connect to your network.

How is BSSID generated?

The BSSID is a 48bit identity used to identify a particular BSS (Basic Service Set) within an area. In Infrastructure BSS networks, the BSSID is the MAC (Medium Access Control) address of the AP (Access Point) and in Independent BSS or ad hoc networks, the BSSID is generated randomly.

What is wireless multiple BSSID setup?

In Multi-SSID mode, the access point creates multiple wireless networks to provide different security and VLAN groups. This mode is suitable when you want your devices connected to different wireless networks and become isolated by VLANs.

How do you get the BSSID of a wireless network Linux?

aircrack-ng can do this. sudo airmon-ng start eth1 6 to use eth1 to monitor channel 6 (the channel is optional) and then you can use sudo airodump-ng eth1 to make it show you the BSSID.


1 Answers

Adapted the answer by @ToonSuperLove, mainly to avoid NPEs.

public class WifiTest extends Activity {

    public void loadWifiAvailableList(EditText etWifiList) {
        WifiManager wifiManager = (WifiManager) 
                                    getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> results = wifiManager.getScanResults();
        String message = "No results. Check wireless is on";
        if (results != null) {
            final int size = results.size();
            if (size == 0) message = "No access points in range";
            else {
                ScanResult bestSignal = results.get(0);
                etWifiList.setText(""); // etWifiList is EditText
                int count = 1;
                for (ScanResult result : results) {
                    etWifiList.append(count++ + ". " + result.SSID + " : "
                            + result.level + "\n" + result.BSSID + "\n"
                            + result.capabilities + "\n"
                            + "\n=======================\n");
                    if (WifiManager.compareSignalLevel(bestSignal.level,
                            result.level) < 0) {
                        bestSignal = result;
                    }
                }
                message = String.format(
                        "%s networks found. %s is the strongest.", size,
                        bestSignal.SSID + " : " + bestSignal.level);
            }
        }
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}
like image 157
Mr_and_Mrs_D Avatar answered Sep 19 '22 19:09

Mr_and_Mrs_D