Wednesday, April 8, 2009

Is Host Reachable

public static boolean isHostReachable(String ip){

boolean pingable = false;
String[] ips = StringUtils.split(ip,".");
byte[] addr2 = new byte[ips.length];
for(int i=0,j; i j = Integer.parseInt(ips[i]);
addr2[i]=(byte)j;
}
try {
pingable = InetAddress.getByAddress(addr2).isReachable(1500);

} catch (UnknownHostException e) {
pingable = false;
log.error(ip + " Indexer Host not reachabe.");
} catch (IOException e) {
pingable = false;
log.error(ip + " Indexer Host not reachabe.");
}
return pingable;
}

No comments:

Post a Comment