如何使用 Java、C# 和/或 C 查找无线网络 (SSID) 列表?

发布于 2024-07-21 13:32:23 字数 89 浏览 7 评论 0 原文

是否有一个工具包/包可供我用来查找适用于 Windows XP+ 的 Java、C# 或 C 语言中可用的无线网络 (SSID) 列表? 任何示例代码将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天邊彩虹 2024-07-28 13:32:23

对于 C#,请查看 托管 Wifi API,它是 本机 Wifi API 随 Windows XP SP2 及更高版本提供。

我尚未测试此代码,但查看托管 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 );
}

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 );
}
枉心 2024-07-28 13:32:23

好吧,您没有指定操作系统,因此对于 Linux,我建议使用 Jean Tourrilhes 的 Wireless Tools for Linux (http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html)。 iwlist() 命令显示有关可用网络的大量信息。 源代码采用 C 语言。另一种方法是使用 libpcap 用 C 语言编写自己的代码,用于捕获信标帧并从中提取 SSID(仅在监视模式下)。 我还没有测试我的嗅探代码,所以我不会将其粘贴到这里,但这是非常简单的工作。

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.

软甜啾 2024-07-28 13:32:23
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)  );
}
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)  );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文