D
D
demetrius20032019-12-11 15:14:57
Android
demetrius2003, 2019-12-11 15:14:57

How to make Android ping external IPs?

Good day! The question is really simple. I am learning Android programming. Made a simple program:

int timeout = 2000;
        InetAddress[] addresses = InetAddress.getAllByName(String.valueOf(ad.getText()));
        for (InetAddress address : addresses)
        {
            if ( address.isReachable(timeout))
            {
                info.setText("OK"); // just set a break point here
            } else {
                info.setText("NOT OK");
            }
        }

Everything is assembled and installed without problems (Already!!!), but there is one misunderstanding - the program only pings internal IP! That is, 127.0.0.1, localhost, default gateway (192.168.1.1) and the second router (192.168.1.2), the phone itself at the address issued by DHCP (192.168.1.204) - ping without problems, but, say, 8.8.8.8 , yandex.ru, and others known to be available for ICMP do not respond! It seems that some settings need to be tweaked somewhere! The isReachable function does not ping external IPs properly! Why?
UPD1: The behavior of the program is the same both in the emulator and on the hardware. In the manifest there are lines allowing the Internet to use.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
demetrius2003, 2019-12-17
@demetrius2003

Atata! Update number one (aka last). It is also a partial solution to the problem. Haven't fully figured it out yet! The above code works fine on some phones and doesn't work at all on others! I modestly assume that the answer lies not in the plane of interaction between Java and Dalvik. The reason is not in the code above, not in manifests and permissions. It is most likely in the core. Somewhere Linux was castrated a little more than completely and voila! ICMP is not present in the phone as a class. I don't know the details. For now, I'm just stating a fact!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question