I am developing a Java program on Windows. I want to access Wi-Fi interface details such as SSID, IP, subnet, enabled or not, connected or not and so on. I am currently trying with using netsh and ipconfig commands.
For example, here is how I get the connected SSID. Is this a good way? Is there any better, easier method? Will this code work with all Windows versions without any problems?
String ssid;
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "netsh wlan show interfaces");
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")){
ssid = line.split("\\s+")[3];
System.out.println(ssid);
return ssid;
}
}