How to find a list of wireless networks (SSID's) in Java, C#, and/or C?

牧云@^-^@ 提交于 2019-12-28 04:58:04

问题


Is there a toolkit/package that is available that I could use to find a list of wireless networks (SSID's) that are available in either Java, C#, or C for Windows XP+? Any sample code would be appreciated.


回答1:


For C#, take a look at the Managed Wifi API, which is a wrapper for the Native Wifi API provided with Windows XP SP2 and later.

I have not tested this code, but looking at the Managed Wifi API sample code, this should list the available SSIDs.

WlanClient client = new WlanClient();
foreach ( WlanClient.WlanInterface wlanIface in client.Interfaces )
{
    // Lists all available networks
    Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList( 0 );
    foreach ( Wlan.WlanAvailableNetwork network in networks )
    {                     
        Console.WriteLine( "Found network with SSID {0}.", GetStringForSSID(network.dot11Ssid));
    }
}

static string GetStringForSSID(Wlan.Dot11Ssid ssid)
{
    return Encoding.ASCII.GetString( ssid.SSID, 0, (int) ssid.SSIDLength );
}



回答2:


ArrayList<String>ssids=new ArrayList<String>();
ArrayList<String>signals=new ArrayList<String>();
ProcessBuilder builder = new ProcessBuilder(
        "cmd.exe", "/c", "netsh wlan show all");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
    line = r.readLine();
    if (line.contains("SSID")||line.contains("Signal")){
        if(!line.contains("BSSID"))
            if(line.contains("SSID")&&!line.contains("name")&&!line.contains("SSIDs"))
            {
                line=line.substring(8);
                ssids.add(line);

            }
            if(line.contains("Signal"))
            {
                line=line.substring(30);
                signals.add(line);

            }

            if(signals.size()==7)
            {
                break;
            }

    }

}
for (int i=1;i<ssids.size();i++)
{
    System.out.println("SSID name == "+ssids.get(i)+"   and its signal == "+signals.get(i)  );
}



回答3:


Well, you didn't specify the OS so, for Linux I will suggest Wireless Tools for Linux by Jean Tourrilhes (http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html). The iwlist() command displays a lot of information about the available networks. The source code is in C. Another way is to write your own code in C using libpcap for capturing the beacon frames and extracting SSID from them (in monitor mode only). I haven't tested my sniffing code yet so I won't paste it here but it is pretty simple job.



来源:https://stackoverflow.com/questions/917910/how-to-find-a-list-of-wireless-networks-ssids-in-java-c-and-or-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!