There is no portable way for a Java program to change the effective user ID; those. Switch from running with root privileges to another user. (And even in C, an application cannot switch between privileged and non-privileged perforce. Switching privileges is a one-way street.)
Reading javadoc for InetAddress.isReachable uses various mechanisms depending on the privileges of the JVM process. However, none of the two approaches used by isReachable will work; eg.
- some firewalls may selectively block ICMP ECHO messages,
- the Echo service on port 7 may not work on the target computer, or port 7 may be blocked by a firewall.
So, I would decide to completely eliminate the problem. Just try to do what you are really trying to do and forget about using isReachable . Or, if it is under your control, fix the machines / networks so that both mechanisms work on the machines you need to check.
@Geek - you say that you cannot test certain ports because they can be blocked. Well , anything can be blocked, including ICMP PING, ICMP ECHO and everything else that you could use to check host availability.
There is only one thing that really matters: can you talk to the service that you are going to use. And there is only one way to find out: try using it.
Or to put it another way, testing if the host is available does not make sense. Hosts unavailable: specific services.
source share