Reputation: 329
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!
P.S. I know about the WifiManager for Android, but I am not developing for Android, I am developing with JDK 6.
Upvotes: 11
Views: 14823
Reputation: 2484
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.
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;
}
Upvotes: 3
Reputation: 850
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.
tl;dr no, sorry
Upvotes: 8