Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Wifi API

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.

like image 273
0101011 Avatar asked Apr 08 '13 00:04

0101011


People also ask

What is API in WiFi?

The Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi, 'cellular', etc.). This can be used to select high definition content or low definition content based on the user's connection.

How do I connect to a specific Wi-Fi network in android programmatically?

First and foremost, add permissions in your manifest file. These 4 permissions are required to make changes in your device network connectivity. Setup configuration to connect one specific wifi using WifiConfiguration. WifiConfiguration config = new WifiConfiguration();

What is the password of this WiFi?

In Network and Sharing Center, next to Connections, select your Wi-Fi network name. In Wi-Fi Status, select Wireless Properties. In Wireless Network Properties, select the Security tab, then select the Show characters check box. Your Wi-Fi network password is displayed in the Network security key box.

What is WiFi manager?

Description. WiFi Manager Lite allows you to manage wireless networks. The application gets you the ability to connect, view details about the wireless networks and set up networks. Moreover, you can manage multiple wireless network profiles.


1 Answers

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;
    }
like image 148
pathe.kiran Avatar answered Sep 28 '22 08:09

pathe.kiran