我正在尝试构建一个基于 Windows 的 Web 小程序来获取 PC 连接到的 SSID!这就是我目前正在做的事情,但我很想看到另一种方法或对此的改进。这个想法是让 JavaScript 向小程序发送请求,然后将来自 Java 小程序的响应附加到文本框的值中。
JavaScript
var ssid = applet.getNetworkParameter("SSID", networkInterface);
爪哇
public String getNetworkParameter(final String parameter, final String arg1){
setAppletStringReturnValue("");
AccessController.doPrivileged(new PrivilegedAction(){
public Object run() {
try {
if (osName.indexOf("win") > -1)
{
this.osNetDriver = new Windows7NetServices();
}
if (parameter.equals("SSID")){
SmartConfig.this.setAppletStringReturnValue(SmartConfig.this.osNetDriver.getSSID(arg1));
}
}
}
return null;
}
});
return this.appletStringValue;
}
public String getSSID(String interfaceName){
try
{
String cmd = "NETSH WLAN SHOW INTERFACE";
boolean parsingAllowed = false;
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line = buf.readLine()) != null)
{
String[] arr = line.split(":");
if (arr.length >= 2)
{
String parameter = arr[0].trim();
String value = arr[1].trim();
if (parameter.equals("Name"))
{
parsingAllowed = value.equals(interfaceName);
}
if ((parameter.equals("SSID")) && (parsingAllowed))
{
return value;
}
}
}
}
return "";
}