@Test public void ipToLongTest() { String ip = "207.97.226.235"; assertEquals(NetUtil.ipToLong(ip), 3479298795L); }
public static long ipToLong(String ip) { if (ip == null) { return -1; } String[] parts = ip.split("\\."); try { return Long.parseLong(parts[0]) << 24 | Long.parseLong(parts[1]) << 16 | Long.parseLong(parts[2]) << 8 | Long.parseLong(parts[3]); } catch (NumberFormatException e) { return -1; } catch (ArrayIndexOutOfBoundsException e) { return -1; } }
NetUtil { public static long ipToLong(String ip) { if (ip == null) { return -1; } String[] parts = ip.split("\\."); try { return Long.parseLong(parts[0]) << 24 | Long.parseLong(parts[1]) << 16 | Long.parseLong(parts[2]) << 8 | Long.parseLong(parts[3]); } catch (NumberFormatException e) { return -1; } catch (ArrayIndexOutOfBoundsException e) { return -1; } } }
NetUtil { public static long ipToLong(String ip) { if (ip == null) { return -1; } String[] parts = ip.split("\\."); try { return Long.parseLong(parts[0]) << 24 | Long.parseLong(parts[1]) << 16 | Long.parseLong(parts[2]) << 8 | Long.parseLong(parts[3]); } catch (NumberFormatException e) { return -1; } catch (ArrayIndexOutOfBoundsException e) { return -1; } }  }
NetUtil { public static long ipToLong(String ip) { if (ip == null) { return -1; } String[] parts = ip.split("\\."); try { return Long.parseLong(parts[0]) << 24 | Long.parseLong(parts[1]) << 16 | Long.parseLong(parts[2]) << 8 | Long.parseLong(parts[3]); } catch (NumberFormatException e) { return -1; } catch (ArrayIndexOutOfBoundsException e) { return -1; } }  static Host parseHost(String str); static Host parseHost(String str, int defaultPort); static List<Host> parseHostList(String str); static boolean hostNameMatch(String hostname, List<Host> list); static boolean hostNameMatch(InetAddress host, List<Host> list); static byte[] getInetAddressAsHex(InetAddress addr); static InetAddress getInetAddressFromHex(String hex); static String inferDomain(); static String getBaseDomain(String host); static String getBaseDomain(String host, boolean tight); static String resolveDottedIP(String ip); static long ipToLong(String ip); static String longToIp(long i); }
NetUtil { public static long ipToLong(String ip) { if (ip == null) { return -1; } String[] parts = ip.split("\\."); try { return Long.parseLong(parts[0]) << 24 | Long.parseLong(parts[1]) << 16 | Long.parseLong(parts[2]) << 8 | Long.parseLong(parts[3]); } catch (NumberFormatException e) { return -1; } catch (ArrayIndexOutOfBoundsException e) { return -1; } }  static Host parseHost(String str); static Host parseHost(String str, int defaultPort); static List<Host> parseHostList(String str); static boolean hostNameMatch(String hostname, List<Host> list); static boolean hostNameMatch(InetAddress host, List<Host> list); static byte[] getInetAddressAsHex(InetAddress addr); static InetAddress getInetAddressFromHex(String hex); static String inferDomain(); static String getBaseDomain(String host); static String getBaseDomain(String host, boolean tight); static String resolveDottedIP(String ip); static long ipToLong(String ip); static String longToIp(long i); static final byte hex; }