Java Utililty Methods InetAddress to

List of utility methods to do InetAddress to

Description

The list of methods to do InetAddress to are organized into topic(s).

Method

longaddressToLong(InetAddress address)
Converts the bytes that make up an internet address into the corresponding integer value to make it easier to perform bit-masking operations on them.
long result = 0;
for (byte element : address.getAddress()) {
    result = (result << 8) + unsign(element);
return result;
intinetAddress2Int(InetAddress addr)
Converts IPv4 InetAddress to 32 bits int.
if (!(addr instanceof Inet4Address)) {
    throw new IllegalArgumentException("Only IPv4 supported");
byte[] addrBytes = addr.getAddress();
return ((addrBytes[0] & 0xFF) << 24) | ((addrBytes[1] & 0xFF) << 16) | ((addrBytes[2] & 0xFF) << 8)
        | ((addrBytes[3] & 0xFF));
intInetAddressToInt(InetAddress ip)
Convert ip to an integer
if (ip == null)
    return -1;
byte[] adr = ip.getAddress();
int[] i = new int[4];
for (int j = 0; j < 4; j++) {
    i[j] = (int) ((adr[j] < 0) ? (256 + adr[j]) : adr[j]);
return i[3] + (i[2] << 8) + (i[1] << 16) + (i[0] << 24);
...
byte[]inetAddressToThriftBinary(InetAddress inetAddress)
inet Address To Thrift Binary
return inetAddress.getAddress();
intipv4AddressToInt(InetAddress addr)
Convert an IPv4 INET address to an integer.
if (addr instanceof Inet6Address)
    throw new IllegalArgumentException("IPv6 address used in IPv4 context");
byte[] a = addr.getAddress();
int res = ((a[0] & 0xFF) << 24) | ((a[1] & 0xFF) << 16) | ((a[2] & 0xFF) << 8) | (a[3] & 0xFF);
return res;
Stringstr(InetAddress address)
str
return address.getHostAddress();
StringtoAddressString(InetAddress ip)
Returns the String representation of an InetAddress .
return toAddressString(ip, false);
StringtoAddrString(InetAddress ip)
to Addr String
checkNotNull(ip);
if (ip instanceof Inet4Address) {
    return ip.getHostAddress();
checkArgument(ip instanceof Inet6Address);
byte[] bytes = ip.getAddress();
int[] hextets = new int[IPV6_PART_COUNT];
for (int i = 0; i < hextets.length; i++) {
...
StringtoDotString(InetAddress ip)
to Dot String
byte[] bytes = ip.getAddress();
String str = new String();
for (int i = 0; i < 4; i++) {
    int b = bytes[i];
    if (b < 0)
        b += 256;
    str += b;
    if (i < 3)
...
int[]toIntArray(InetAddress addr)
Convert an IP address int array.
try {
    byte[] bytes = addr.getAddress();
    String ip = addr.getHostAddress();
    int[] result = null;
    if (addr instanceof Inet6Address) {
        result = new int[8];
        String[] comp = ip.split(":");
        for (int i = 0; i < comp.length; i++)
...