import java.net.*; import java.io.*; public class ReachableNegHostTest { public static void main(String args[]) { if(args.length != 2) { System.out.println("Usage: java ReachableHostTest "); System.exit(1); } InetAddress hostnames[] = new InetAddress[2]; String tempStr = null; for(int i=0; i<2; i++) { try { tempStr = args[i]; hostnames[i] = InetAddress.getByName(tempStr); } catch (UnknownHostException e) { System.err.println("UnknownHostException thrown. Test failed."); System.err.println("The unknown host is : " + tempStr); e.printStackTrace(); System.exit(1); } } try { if(hostnames[0].isReachable(1) && hostnames[1].isReachable(1)) { System.out.println("FAILURE!! Both the hosts should not be reachable within 1 millisecond"); System.exit(1); } else { System.out.println("Passed."); } } catch (IOException e) { System.err.println("IOException occured."); e.printStackTrace(); System.exit(1); } } }