Reputation: 1715
I am trying to get the unreachable condition of the ping host as I am getting just (0,1) value for up and down respectively, how would I get any condition "2" at which it tell me unreachable ping host?
My code,
import java.net.InetAddress;
public class PingExample
{
public static void main(String[] args)
{
try
{
InetAddress address = InetAddress.getByName("172.16.2.0");
// Try to reach the specified address within the timeout
// periode. If during this periode the address cannot be
// reach then the method returns false.
boolean reachable = address.isReachable(10000);
System.out.println("Is host reachable? " + reachable);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
What is active and passive state? How can I check it?
Edit: see at this link page 26 http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf
stat column description. I want to get this result as I had posted my code, so how would I get that column "state"? Remember I am using loop for "n" hosts.
Upvotes: 0
Views: 6929
Reputation: 718798
"Up" means host pinged "down" means tried to ping but fail because sys is off and "unreachable" means that it tried to ping but connection did not completed so that it would tell either the pinged host is "up" or "down"!
This does not make sense from a technical perspective, and I suspect that means that what you are trying to do doesn't make any sense either.
For the record:
Ping doesn't involve making connections. It it is a simple request and response. What happens is that an ICMP Echo Request packet is sent, and you wait for a few seconds to see if you get an ICMP Echo Reply packet.
You might also get an ICMP Network Unreachable or an ICMP Host Unreachable ... if the packet cannot be routed.
You might also get ... nothing. You can't reliably distinguish between "system is broken / off", "packets are getting lost by the network", "packets are being filtered out" and "system doesn't exist". These all give you ... no reply, in some cases.
These days, responses (or non-responses) to pings are often due to firewalls blocking unwanted traffic and the like.
So what this all means that it is not possible to reliably distinguish between "down" and "unreachable" ... even if you could provide an explanation for a distinction that made technical sense.
And we haven't talked about how much of this information makes it back to a Java application.
Upvotes: 2