-4

iam new to java programming and my final year project is based on a Rogue Access point detection tool, and i need to how can i obtain SSID from a java code of the exisiting wifi networks?

for eg: say iam in my laptop i need the program to show how many SSIDs are there broadcasting the SSIDS and the names! (through the built in wifi adapter in the laptop).

Thank you.

  • 1
    What OS? What wireless chipset? What driver? This question is woefully incomplete and you'll have to do a lot of homework here. – tadman Nov 19 '17 at 02:42
  • 2
    Seems like you put absolutely zero effort into this yourself, including not even making an effort to search. If you had, you would have seen https://stackoverflow.com/q/5378103/62576 We're not your personal research assistants. It's **your** final year project. Do the work to earn your own grade. – Ken White Nov 19 '17 at 02:42
  • thank you for the help! i did and i found the link which you clearly described, but later on when analyzing i saw that it isn't possible to access lower network details that's why i wanted to re ask the question! thank you for your kind help. – Harith Adikaram Nov 19 '17 at 06:12

1 Answers1

0

Java is a High-Level, Platform-Independent programming language. Network settings, and how you control them will depend on your Operating System, and to my knowledge there is no simple way or an API to expose this,but i tried write a code maybe is helpful for you.

Code :

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Electron-Eddine
 */
public class Network {

    ArrayList<String> localNetworks = new ArrayList<>();

    public static void main(String[] args) throws IOException {

        new network.Network().display(new Network().getNetwokrs());
        new Network().searchSystemNetwork(new Network().getNetwokrs());
    }

    public ArrayList<String> getNetwokrs() throws IOException {

        ProcessBuilder builder = new ProcessBuilder(
                "cmd.exe", "/c", "netsh wlan show networks mode=Bssid");
        builder.redirectErrorStream(true);
        Process p = builder.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String lineCommand;
        String network ;
        while (true) {
            lineCommand = r.readLine();
            if (lineCommand == null) {
                break;
            } else if (lineCommand.contains("SSID")&&!lineCommand.contains("BSSID")) {
                String[] networks = lineCommand.split(":", 2);
                network = networks[1];
                if (!network.equals(" ")) {
                    String pureNetworkName = network.trim();
                    localNetworks.add(pureNetworkName);
                } else {
                    return null;
                }
            }

        }
        return localNetworks;
    }

    private void display(ArrayList<String> networks) {
        networks.forEach(network -> {
            System.out.println(network);
        });
    }

    private void searchSystemNetwork(ArrayList<String> networks) {
        String REQUIRED_NETWORK = "PEER2PEER";
        networks.forEach(network -> {
            if (network.equals(REQUIRED_NETWORK)) {
                System.out.println("Network is availabale");

            } else {

            }
        });
    }
    void create()
    {

     //  Netsh WLAN export profile key=clear folder="Folder_Path" 
    }

}

Output :

run:

PEER2PEER

condor PGN522

Ammar_A

Network is availabale

BUILD SUCCESSFUL (total time: 1 second)