NetUtils { public static InetAddress getInetAddress(int address) { InetAddress ip = null; try { ip = InetAddress.getByAddress(NetUtils.intToByteArray4(address)); } catch (UnknownHostException e) { LOG.error("", e); } return ip; } private  NetUtils(); static int byteArray4ToInt(byte[] ba); static long byteArray6ToLong(byte[] ba); static byte[] longToByteArray6(long addr); static byte[] intToByteArray4(int value); static InetAddress getInetAddress(int address); static InetAddress getInetNetworkMask(int prefixMaskLength, boolean isV6); static int getSubnetMaskLength(byte[] subnetMask); static int getSubnetMaskLength(InetAddress subnetMask); static InetAddress getSubnetPrefix(InetAddress ip, int maskLen); static boolean inetAddressConflict(InetAddress testAddress, InetAddress filterAddress, InetAddress testMask,
            InetAddress filterMask); static boolean isZeroMAC(byte[] mac); static boolean isBroadcastMACAddr(byte[] macAddress); static boolean isUnicastMACAddr(byte[] macAddress); static boolean isMulticastMACAddr(byte[] macAddress); static boolean isAny(InetAddress ip); static boolean fieldsConflict(int field1, int field2); static InetAddress parseInetAddress(String addressString); static boolean isIPv4AddressValid(String cidr); static boolean isIPv6AddressValid(String cidr); static boolean isIPAddressValid(String cidr); static int getUnsignedByte(byte value); static int getUnsignedShort(short value); static InetAddress gethighestIP(boolean v6); static byte[] getBroadcastMACAddr(); static final int NUM_BITS_IN_A_BYTE; static final int MAC_ADDR_LENGTH_IN_BYTES; static final int MAC_ADDR_LENGTH_IN_WORDS; }
@Test public void testInetMethods() throws UnknownHostException { int ip = 0xfffffff0; InetAddress inet = InetAddress.getByName("255.255.255.240"); assertTrue(inet.equals(NetUtils.getInetAddress(ip))); ip = 0; inet = InetAddress.getByName("0.0.0.0"); assertTrue(inet.equals(NetUtils.getInetAddress(ip))); ip = 0x9ffff09; inet = InetAddress.getByName("9.255.255.9"); assertTrue(inet.equals(NetUtils.getInetAddress(ip))); }