0

I'm working on a local network scanner. Today I obtain all ip and mac addresses with this:

@Override
    protected List<Camera> doInBackground(String... params) {
        for (int i = 0; i < 255 && !isCancelled(); i++) {
            String ip = params[0] + String.valueOf(i);
            try {
                Runtime.getRuntime().exec("ping -b " + ip);
            } catch (IOException e) {
                if (Constants.ENABLE_LOGS) {
                    e.printStackTrace();
                }
                Log.e(getClass().getName(), e.getMessage());
            }
        }
        return searchCameras();
    }

 private List<Camera> searchCameras() {
        List<Camera> cams = new ArrayList<>();
        try {
            BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
            String line = "";
            int cameraCompleted = 0, cameraPosition = -1;
            while ((line = br.readLine()) != null /*|| cameraCompleted < mLanCamList.size()*/) {
                String[] tokens = line.split("\\s+");
                String CAM_MAC = "ec:ba:fe";
                if (tokens.length >= 4 && tokens[3].startsWith(CAM_MAC)) {
                    if (cameraPosition != -1) {
                        mLanCamList.get(cameraPosition).setIp(tokens[0]);
                        cameraCompleted+=1;
                    }
                }
            }
            br.close();
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return cams;
    }

As you can see, the IP address is missing for all items. I have tried InetAddress but it returns just the same IP.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Maxime Vince
  • 75
  • 1
  • 9
  • You say "as you can see" - however I do not see what you mean. Please update your question. – Robert Sep 06 '16 at 11:19
  • In my variable token, i have the IP adress and the MAC adress and not the SSID – Maxime Vince Sep 06 '16 at 11:31
  • Yes, because the SSID is the network name. It is never used on IP layer. If you want the SSID of the current network see [here](http://stackoverflow.com/questions/21391395/get-ssid-when-wifi-is-connected). – Robert Sep 06 '16 at 12:17

0 Answers0