如何在 Java、C# 和/或 C 中查找无线网络 (SSID) 列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/917910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find a list of wireless networks (SSID's) in Java, C#, and/or C?
提问by Taylor Leese
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.
是否有可用的工具包/包,我可以使用它来查找适用于 Windows XP+ 的 Java、C# 或 C 中可用的无线网络 (SSID) 列表?任何示例代码将不胜感激。
采纳答案by Dan Walker
For C#, take a look at the Managed Wifi API, which is a wrapper for the Native Wifi APIprovided with Windows XP SP2 and later.
对于 C#,请查看Managed Wifi API,它是Windows XP SP2 及更高版本提供的Native Wifi API的包装器。
I have not tested this code, but looking at the Managed Wifi API sample code, this should list the available SSIDs.
我尚未测试此代码,但查看托管 Wifi API 示例代码时,应该会列出可用的 SSID。
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 );
}
回答by Abhishek Anand
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.
好吧,您没有指定操作系统,因此对于 Linux,我会推荐 Jean Tourrilhes 的适用于 Linux 的无线工具 ( http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html)。iwlist() 命令显示有关可用网络的大量信息。源代码是用 C 编写的。另一种方法是使用 libpcap 用 C 编写自己的代码来捕获信标帧并从中提取 SSID(仅在监控模式下)。我还没有测试我的嗅探代码,所以我不会在这里粘贴它,但它是非常简单的工作。
回答by Alireza Taghizadeh
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) );
}