Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subnet Scanner not showing all the devices. #33

Open
eakteam opened this issue Jan 3, 2018 · 17 comments
Open

Subnet Scanner not showing all the devices. #33

eakteam opened this issue Jan 3, 2018 · 17 comments

Comments

@eakteam
Copy link

eakteam commented Jan 3, 2018

Hello thanks for this great library first off. I have noticed that Subnet/LAN Scanner is not showing all the devices. I think this is happening because when it pings the IPs with NATIVE ping some type of devices may returns : no answer yet for icmp_seq from native terminal ,but this types show be added as online devices because they just don't accepts ping , but they are there ....
Sorry for my low English hope to be fixed soon.

i think you should check the output of Ping Process and if they returns timeout its ok they are right there 👍

Pattern M = Pattern.compile("(^[\\d]+) bytes from ([^:]+): icmp_seq=([^ ]+) ttl=([\\d]+) time=([^ ]+) ms");
                                Matcher MM = M.matcher(readData);
                                // TimeOut
                                Pattern M6 = Pattern.compile("^no answer yet for icmp_seq=([\\d]+)");
                                Matcher MM6 = M6.matcher(readData);
@stealthcopter
Copy link
Owner

stealthcopter commented Jan 3, 2018

Hi @eakteam Can you try increasing the timeout of the scan to see if more devices are discovered? Maybe 5 - 10 seconds is enough

SubnetDevices.fromLocalAddress().setTimeoutMillis(10000).findDevices(new SubnetDevices.OnSubnetDeviceFound() {
    @Override
    public void onDeviceFound(Device device) {
        // Stub: Found subnet device
    }

    @Override
    public void onFinished(ArrayList<Device> devicesFound) {
        // Stub: Finished scanning
    }
});

@eakteam
Copy link
Author

eakteam commented Jan 3, 2018

Hello , i just tried to set the timeout to 10000 ms , it's the same thing. Anyway i don't think that the problem stay in the ping responding timeout. In fact your implementation work really good for devices that accept ICMP ping request , but there are some other types of devices that they don't allow that and returns "timeout" .... to try to explain well this is my implementation of LAN Scanner in my App , i wish to replace with yours.

boolean filloi;
                    Process p = null;
                    try {
                        p = Runtime.getRuntime().exec("ping " + "-v " + "-c " + 1 + " " + testIp);
                        filloi = true;
                    } catch (IOException e) {
                        filloi = false;
                        e.printStackTrace();
                    }
                    String readData;
                    if (filloi) {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        BufferedReader reader1 = new BufferedReader(new InputStreamReader(p.getErrorStream()));

                        while ((readData = reader.readLine()) != null) {
                            Log.d("PINGIMI", readData);
                            totalReadData.add(readData);

                            if (!readData.startsWith("---")) {
                                // Pergjigje ping
                                Pattern M = Pattern.compile("(^[\\d]+) bytes from ([^:]+): icmp_seq=([^ ]+) ttl=([\\d]+) time=([^ ]+) ms");
                                Matcher MM = M.matcher(readData);
                                // Statistikat e pingimit
                                Pattern M3 = Pattern.compile("(^[\\d]+) packets transmitted, ([^ ]+) received, ([\\d]+)% packet loss, time ([^ ]+)ms");
                                Matcher MM3 = M3.matcher(readData);
                                // TimeOut
                                Pattern M6 = Pattern.compile("^no answer yet for icmp_seq=([\\d]+)");
                                Matcher MM6 = M6.matcher(readData);

                                if (MM.find()) // Ping OK
                                {
                                    // HERE I ADD DEVICES THAT RESPONDS TO PING
                                }
                                else if (MM6.find()) // Timeout
                                {
                                    // HERE ADD DEVICES TOO THAT RETURN TIMEOUT BUT THEY ARE ONLINE IN THAT LAN
                                }

@stealthcopter
Copy link
Owner

Ok, so to confirm you have some devices that don't respond to ping and they cause the native ping binary to output "no answer yet for icmp_seq="? I don't think it'd be a good idea to return a positive match in this case as this could also be the same output for a device that don't exist.

@eakteam
Copy link
Author

eakteam commented Jan 4, 2018

Yes , the problem is that you are just checking the negative or positive results of ping binary and than calculate the results. In fact you should parse and read the results before and after that calculate if they should be added or not as Online Devices. So "no answer yet for icmp_seq=" may returned from some devices which they have disabled ping feature to reply back maybe because of protecting from DDOS , but anyway those devices are in the network and working. Sorry for my low English , hope to understand what im trying to say :) :D :)

@stealthcopter
Copy link
Owner

Ok, I understand. Can you send the full output of ping to one of these devices?

@eakteam
Copy link
Author

eakteam commented Jan 4, 2018

THIS ARE THE COMMON TERMINAL OUTPUT OF PING BINARY :

// Ping
Pattern M = Pattern.compile("(^[\\d]+) bytes from ([^:]+): icmp_seq=([^ ]+) ttl=([\\d]+) time=([^ ]+) ms");
// Time Stats
Pattern M1 = Pattern.compile("^rtt [^0-9]*([\\d][^/]+)/([^/]+)/([^/]+)/([^ ]+) ms$");
// Host Unreachable
Pattern M2 = Pattern.compile("\\bFrom ([^:]+): icmp_seq=([^ ]+) (Destination Host Unreachable)");
// Ping Stats
Pattern M3 = Pattern.compile("(^[\\d]+) packets transmitted, ([^ ]+) received, ([\\d]+)% packet loss, time ([^ ]+)ms");
// Error Stats
Pattern M4 = Pattern.compile("(^[\\d]+) packets transmitted, ([^ ]+) received, [+]([^ ]+) errors, ([\\d]+)% packet loss, time ([^ ]+)ms");
// Network Unreachable
Pattern M5 = Pattern.compile("^[ping:]+ [sendmg:]+ ([Network isunachbl]+)");
// TimeOut
Pattern M6 = Pattern.compile("^no answer yet for icmp_seq=([\\d]+)");
//TTL Expired
Pattern M7 = Pattern.compile("\\bFrom ([^:]+): icmp_seq=([^ ]+) (Time to live exceeded)");

When the device is there but i doesn't allow ping it send to the console Pattern M6 when it is not there maybe it returns Unreachable or Nothing just end the execution

@stealthcopter
Copy link
Owner

stealthcopter commented Jan 4, 2018

Can I see the output of ping directly? like this

 admin@192.168.0.2 ~ $ ping -v -i 1 192.168.0.3
 PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
 64 bytes from 192.168.0.3: icmp_req=1 ttl=64 time=0.233 ms

@eakteam
Copy link
Author

eakteam commented Jan 4, 2018

NORMAL DEVICE PING :

shell@hct6580_weg_c_m:/ $ ping -v -c 1 192.168.88.1
PING 192.168.88.1 (192.168.88.1) 56(84) bytes of data.
64 bytes from 192.168.88.1: icmp_seq=1 ttl=64 time=157 ms

--- 192.168.88.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 157.430/157.430/157.430/0.000 ms

DEVICE DONT EXIST ON NETWORK :

shell@hct6580_weg_c_m:/ $ ping -v -c 1 192.168.88.88
PING 192.168.88.88 (192.168.88.88) 56(84) bytes of data.
From 192.168.88.152: icmp_seq=1 Destination Host Unreachable

--- 192.168.88.88 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

DEVICE EXIST BUT IT DON'T ACCEPT PING ( This is not found in ur lib)

1|shell@hct6580_weg_c_m:/ $ ping -v -c 1 192.168.88.21
PING 192.168.88.21 (192.168.88.21) 56(84) bytes of data.

--- 192.168.88.21 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

Here it returns nothing as message from ping binary... But they may return "no answer yet from icmp_seq" if you increase the ping count to 2 : "-c 2" . Those type of devices should be marked as Online in the LAN.

@nikhilgarg89
Copy link

@eakteam @stealthcopter are you able do some workaround for this?

@eakteam
Copy link
Author

eakteam commented Jul 9, 2018

I have solved it in my app by self writing all the ping class...
The workaround is :

DEVICE EXIST BUT IT DON'T ACCEPT PING ( This is not found in ur lib)

1|shell@hct6580_weg_c_m:/ $ ping -v -c 1 192.168.88.21
PING 192.168.88.21 (192.168.88.21) 56(84) bytes of data.

--- 192.168.88.21 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
Here it returns nothing as message from ping binary... But they may return "no answer yet from icmp_seq" if you increase the ping count to 2 : "-c 2" . Those type of devices should be marked as Online in the LAN.

@osfunapps
Copy link

@eakteam can you fork the library and show the fix you made? I too struggling with this thing. Not all devices found on the network :(

@eakteam
Copy link
Author

eakteam commented Mar 4, 2019

Hi @osfunapps , this would be great to help but i have solved it with my own implementation. I am not using this lib implementation. But i can say that the issue is happening because of native ping results. So there is a case when devices doesn't reply to ping request but in fact they are active on LAN. So just try to "play" with the ping results when executed by Android process. You may understand the issue.

Anyway, i will try to post the solution here later because i can't for the moment.

@eakteam
Copy link
Author

eakteam commented Jul 21, 2020

@BrentPollyn , i have implemented in my app, custom subnet scanner. This library needs much changes to full support it and being compatible with Android 10+ since they disabled access to sys/arp too

@eakteam
Copy link
Author

eakteam commented Jul 21, 2020

@BrentPollyn , i am sorry but my source code cannot be shared. The app which contains it is : https://play.google.com/store/apps/details?id=com.eakteam.networkmanager.pro

Try to implement it yourself it is not so much to write.
I suggest you

  1. First make an ip neightbour scan and cache all IP in range
  2. Make a ICMP request to all IPs in range
  3. Who responds get the MAC address, make a request to external API to find the vendor from the MAC, and display it together with their IP address.

Sorry for my nit good English, hope to be understandable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@stealthcopter @nikhilgarg89 @eakteam @osfunapps and others