@Test public void getIpNum() throws Exception { long a = IpUtils.getIpNum("192.168.2.1"); long b = IpUtils.getIpNum("192.168.1.254"); Assert.assertTrue(a > b); }
public static long getIpNum(String ipAddress) { if (!isValidIPv4(ipAddress)) { throw new BusinessException("IpUtils.getIpNum:传入的IP地址[" + ipAddress + "]无效，请检查！"); } String[] ip = ipAddress.split("\\."); long a = Integer.parseInt(ip[0]); long b = Integer.parseInt(ip[1]); long c = Integer.parseInt(ip[2]); long d = Integer.parseInt(ip[3]); long ipNum = a * IP_MULTIPLE_A + b * IP_MULTIPLE_B + c * IP_MULTIPLE_C + d; return ipNum; }
IpUtils { public static long getIpNum(String ipAddress) { if (!isValidIPv4(ipAddress)) { throw new BusinessException("IpUtils.getIpNum:传入的IP地址[" + ipAddress + "]无效，请检查！"); } String[] ip = ipAddress.split("\\."); long a = Integer.parseInt(ip[0]); long b = Integer.parseInt(ip[1]); long c = Integer.parseInt(ip[2]); long d = Integer.parseInt(ip[3]); long ipNum = a * IP_MULTIPLE_A + b * IP_MULTIPLE_B + c * IP_MULTIPLE_C + d; return ipNum; } }
IpUtils { public static long getIpNum(String ipAddress) { if (!isValidIPv4(ipAddress)) { throw new BusinessException("IpUtils.getIpNum:传入的IP地址[" + ipAddress + "]无效，请检查！"); } String[] ip = ipAddress.split("\\."); long a = Integer.parseInt(ip[0]); long b = Integer.parseInt(ip[1]); long c = Integer.parseInt(ip[2]); long d = Integer.parseInt(ip[3]); long ipNum = a * IP_MULTIPLE_A + b * IP_MULTIPLE_B + c * IP_MULTIPLE_C + d; return ipNum; }  }
IpUtils { public static long getIpNum(String ipAddress) { if (!isValidIPv4(ipAddress)) { throw new BusinessException("IpUtils.getIpNum:传入的IP地址[" + ipAddress + "]无效，请检查！"); } String[] ip = ipAddress.split("\\."); long a = Integer.parseInt(ip[0]); long b = Integer.parseInt(ip[1]); long c = Integer.parseInt(ip[2]); long d = Integer.parseInt(ip[3]); long ipNum = a * IP_MULTIPLE_A + b * IP_MULTIPLE_B + c * IP_MULTIPLE_C + d; return ipNum; }  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 long getIpNum(String ipAddress) { if (!isValidIPv4(ipAddress)) { throw new BusinessException("IpUtils.getIpNum:传入的IP地址[" + ipAddress + "]无效，请检查！"); } String[] ip = ipAddress.split("\\."); long a = Integer.parseInt(ip[0]); long b = Integer.parseInt(ip[1]); long c = Integer.parseInt(ip[2]); long d = Integer.parseInt(ip[3]); long ipNum = a * IP_MULTIPLE_A + b * IP_MULTIPLE_B + c * IP_MULTIPLE_C + d; return ipNum; }  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; }