Java - Wifi API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15869578/
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
Java - Wifi API
提问by 0101011
I am trying to find out if there is a Wifi API for Java. Something that can connect to Wifi networks and scan them (to find devices). I can't seem to find something like that. Any suggestions? Thanks!
我想知道是否有适用于 Java 的 Wifi API。可以连接到 Wifi 网络并扫描它们(以查找设备)的东西。我似乎无法找到类似的东西。有什么建议?谢谢!
P.S. I know about the WifiManager for Android, but I am not developing for Android, I am developing with JDK 6.
PS 我知道适用于 Android 的 WifiManager,但我不是为 Android 开发,而是使用 JDK 6 进行开发。
回答by hatkirby
Wireless networking cards differ greatly depending on manufacturer and even version, and most operating systems do not have a standardized way of interacting with them. Some computers do not even come with wireless cards. The reason it works so well with Android is because Google can guarantee that every phone that has Android installed has a proper wireless networking interface.
无线网卡因制造商甚至版本的不同而有很大差异,并且大多数操作系统都没有与之交互的标准化方式。有些计算机甚至没有配备无线网卡。它在 Android 上运行良好的原因是因为 Google 可以保证每部安装了 Android 的手机都有一个合适的无线网络接口。
tl;dr no, sorry
tl;博士不,对不起
回答by pathe.kiran
You can take help of command line tools to get list of available networks using command "netsh wlan show networks mode=Bssid". Try below java method.
您可以借助命令行工具使用命令“netsh wlan show networks mode=Bssid”获取可用网络列表。试试下面的java方法。
public static ArrayList scanWiFi() {
ArrayList<String> networkList = new ArrayList<>();
try {
// Execute command
String command = "netsh wlan show networks mode=Bssid";
Process p = Runtime.getRuntime().exec(command);
try {
p.waitFor();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream())
);
String line;
StringBuilder sb = new StringBuilder();
String ssidArr[];
while ((line = reader.readLine()) != null) {
//System.out.println(line);
if (line.contains("SSID ") && !line.contains("BSSID ")) {
sb.append(line);
networkList.add(line.split(":")[1]);
//System.out.println("data : " + ssidArr[1]);
}
}
//System.out.println(networkList);
} catch (IOException e) {
}
return networkList;
}