List of utility methods to do InetAddress from
InetAddress | inetAddress(String host) inet Address try { return InetAddress.getByName(host); } catch (UnknownHostException e) { throw new IllegalArgumentException(e); |
InetAddress | int2InetAddress(int val) Converts 32 bits int to IPv4 InetAddress. byte[] value = { (byte) ((val & 0xFF000000) >>> 24), (byte) ((val & 0X00FF0000) >>> 16), (byte) ((val & 0x0000FF00) >>> 8), (byte) ((val & 0x000000FF)) }; try { return InetAddress.getByAddress(value); } catch (UnknownHostException e) { return null; |
InetAddress | IntegerToInetAddress(int ipAddress) Integer To Inet Address byte[] array = new byte[4]; array[0] = (byte) ((ipAddress >> 24) & 0xFF); array[1] = (byte) ((ipAddress >> 16) & 0xFF); array[2] = (byte) ((ipAddress >> 8) & 0xFF); array[3] = (byte) (ipAddress & 0xFF); return InetAddress.getByAddress(array); |
InetAddress | intToInetAddress(int i) int To Inet Address return InetAddress.getByAddress(intToAddress(i));
|
long | ip2Long(InetAddress ip) Converts an IP v4 number to a 64bit (long) number, according to the lobby protocol standard. long res; byte[] addr = ip.getAddress(); final long f1 = (long) addr[0] << 24; final long f2 = (long) addr[1] << 16; final long f3 = (long) addr[2] << 8; final long f4 = (long) addr[3]; res = f1 + f2 + f3 + f4; return res; ... |
byte[] | ipToBytesByInetAddress(String ip) ip To Bytes By Inet Address return InetAddress.getByName(ip).getAddress();
|
long | ipToLong(InetAddress ip) ip To Long byte[] octets = ip.getAddress(); long result = 0; for (byte octet : octets) { result <<= 8; result |= octet & 0xff; return result; |
InetAddress | long2InetAddress(long val) Converts 32 bits int packaged into a 64bits long to IPv4 InetAddress. if ((val < 0) || (val > 0xFFFFFFFFL)) { return int2InetAddress((int) val); |
InetAddress | toInetAddress(String host) Converts a hostname or IP address into a InetAddress. InetAddress addr = null; if (host.length() > 0) { try { addr = InetAddress.getByName(host); int periodCount = 0; if (isMaybeIpAddress(host, periodCount)) { String canHostNm = addr.getCanonicalHostName(); String hostNm = addr.getHostName(); ... |