@Test public void isReachable() throws Exception { String ip = "127.0.0.1"; Assert.assertTrue(IpUtils.isReachable(ip)); }
public static boolean isReachable(String ip) { if (!isValidIPv4(ip)) { return false; } boolean isReachable; try { InetAddress address = InetAddress.getByName(ip); int timeout = 2000; logger.info("正在测试IP地址[" + ip + "]的连通性..."); isReachable = address.isReachable(timeout); } catch (Exception e) { isReachable = false; logger.info("IP地址[" + ip + "]无法联通", e); } return isReachable; }
IpUtils { public static boolean isReachable(String ip) { if (!isValidIPv4(ip)) { return false; } boolean isReachable; try { InetAddress address = InetAddress.getByName(ip); int timeout = 2000; logger.info("正在测试IP地址[" + ip + "]的连通性..."); isReachable = address.isReachable(timeout); } catch (Exception e) { isReachable = false; logger.info("IP地址[" + ip + "]无法联通", e); } return isReachable; } }
IpUtils { public static boolean isReachable(String ip) { if (!isValidIPv4(ip)) { return false; } boolean isReachable; try { InetAddress address = InetAddress.getByName(ip); int timeout = 2000; logger.info("正在测试IP地址[" + ip + "]的连通性..."); isReachable = address.isReachable(timeout); } catch (Exception e) { isReachable = false; logger.info("IP地址[" + ip + "]无法联通", e); } return isReachable; }  }
IpUtils { public static boolean isReachable(String ip) { if (!isValidIPv4(ip)) { return false; } boolean isReachable; try { InetAddress address = InetAddress.getByName(ip); int timeout = 2000; logger.info("正在测试IP地址[" + ip + "]的连通性..."); isReachable = address.isReachable(timeout); } catch (Exception e) { isReachable = false; logger.info("IP地址[" + ip + "]无法联通", e); } return isReachable; }  static String getIP4WithPriority(); static String getLocalHostAddress(); static boolean isValidIPv4(String ip); static boolean isValidPort(String port); static List<InetAddress> getIP4ByNetworkInterface(); static boolean isInnerIP(String ipAddress); static long getIpNum(String ipAddress); static boolean isReachable(String ip); }
IpUtils { public static boolean isReachable(String ip) { if (!isValidIPv4(ip)) { return false; } boolean isReachable; try { InetAddress address = InetAddress.getByName(ip); int timeout = 2000; logger.info("正在测试IP地址[" + ip + "]的连通性..."); isReachable = address.isReachable(timeout); } catch (Exception e) { isReachable = false; logger.info("IP地址[" + ip + "]无法联通", e); } return isReachable; }  static String getIP4WithPriority(); static String getLocalHostAddress(); static boolean isValidIPv4(String ip); static boolean isValidPort(String port); static List<InetAddress> getIP4ByNetworkInterface(); static boolean isInnerIP(String ipAddress); static long getIpNum(String ipAddress); static boolean isReachable(String ip); static final String LOCALHOST; static final String ANYHOST; }