I'm making an ISP logger, that fires an event when I loose internet connectivity.
The trigger is when I no longer can resolve "www.google.com", which in turn starts a network diagnose process.
My idea is to ping my router, the modem and an external ip, to try to pinpoint where the problem is.
The problem I'm facing is that creating an InetAddress with getByName("192.168.0.1") is of no use when the DNS is no longer available:
InetAddress ia = InetAddress.getByName("192.168.0.1"); if (ia.isReachable(1000)) { System.out.println("This works if the DNS server is available"); } else { System.out.println("But it doesn't if DNS is not available."); System.out.println("Although my reason for trying to ping the IP is exactly the reason it's not working:"); System.out.println("The DNS server is no longer responding!"); }
So my obvious question is how do I do this without a DNS (or host file) present?
Would converting a String "192.168.0.1" to a byte array {192, 168, 0, 1} and using getByAddress() work?
byte addr[] = {(byte) 192, (byte) 168, 0, 1}; InetAddress ia = InetAddress.getByAddress(addr); if (ia.isReachable(1000)) { System.out.println("Host is reachable, but will this be true if DNS isn't available?"); }
Martin