Reputation: 51
I'm trying to get the SSID of my wireless network device in Java. I tried the official network tutorials http://java.sun.com/docs/books/tutorial/networking/nifs/retrieving.html but getDisplayName() getName() don't return SSID. Is there a way to get an exact SSID? Also, I'm also trying to read the wifi signal strength of all my network devices and couldn't find a way to do it. Can anyone please direct me from where to get all these information (tutorials, code samples etc)?
Upvotes: 3
Views: 6302
Reputation: 11
This is code sample where current connected wireless SSID is returned from cmd
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")){
// do something
}
}
Upvotes: 0
Reputation: 16736
This cannot be done using pure Java. The Java API can take you as low as the NetworkInterface level in the networking stack, but not lower. When connected to a WiFi network, all SSID, handshaking and security stuff is done in lower levels than that - namely, your platform-dependent driver. The Java API (as of Java7) doesn't let you any closer to this information; you will have to use some platform-dependent code for that.
Upvotes: 1