我需要使用 Java 获取附近的 BSSID 及其信号强度。类似的输出netsh wlan show networks mode=BSSID
。
可能吗?
尝试实现这样的方法:(当然,cmd 字符串中保存的命令仅适用于窗口操作系统)。
"wlanResults.append("...");" 只是将结果写入gui 中的 jTextArea(它是我正在处理的程序的一部分)。
public void getWLANbssidInfo(){
String cmd = "netsh wlan show network mode=bssid";
try {
Process p3;
p3 = Runtime.getRuntime().exec("cmd /c " + cmd);
p3.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p3.getInputStream()));
String line = reader.readLine();
while(line!=null){
wlanResults.append(line + "\n");
System.out.println(line);
line = reader.readLine();
}
} catch (IOException ex) {
wlanResults.append("Comand error\n" + ex);
System.out.println("There was an IO exception.");
} catch (InterruptedException ex) {
wlanResults.append("Command was interrupted: " + ex);
System.out.println("The command was interrupted.");
}
}