Java Utililty Methods IP Address to String

List of utility methods to do IP Address to String

Description

The list of methods to do IP Address to String are organized into topic(s).

Method

StringipToString(long ip)
ip To String
return ipToString(new StringBuilder(), ip).toString();
Stringipv4ToBinaryStr(int ipv4)
Converts an IPv4 address from integer to a 32 bit binary representation (e.g., "11100100...").
StringBuilder[] strBuilder = new StringBuilder[4];
for (int i = 0; i < 4; i++) {
    strBuilder[i] = new StringBuilder(0);
    short b = (short) (ipv4 & 0xff);
    ipv4 >>= 8;
    short mask = (short) 128;
    for (int j = 0; j < 8; j++) {
        if ((b & mask) == mask) {
...
Stringipv4ToStr(int ipv4)
Converts an IPv4 address from integer representation to dotted decimal notation (e.g., "192.168.1.1").
short[] decimals = new short[4];
for (int i = 0; i < 4; i++) {
    decimals[i] = (short) (ipv4 & 0xff);
    ipv4 >>= 8;
String dottedStr = Short.toString(decimals[3]) + "." + Short.toString(decimals[2]) + "."
        + Short.toString(decimals[1]) + "." + Short.toString(decimals[0]);
return dottedStr;
...
Stringipv4ToString(byte[] address)
ipv To String
return (address[0] & 0xFF) + "." + (address[1] & 0xFF) + "." + (address[2] & 0xFF) + "."
        + (address[3] & 0xFF);
StringipV4ToString(int ip)
ip V To String
return String.format("%d.%d.%d.%d", (ip >> 24 & 0xff), (ip >> 16 & 0xff), (ip >> 8 & 0xff), (ip & 0xff));
longipV4ToLong(final String ipaddress)
Convert an IP Address to a long.
final String SOURCE = "NetworkScannerHelper.ipV4ToLong() ";
final byte[] arrayBytes;
final int octet1;
final int octet2;
final int octet3;
final int octet4;
long longAddress;
arrayBytes = InetAddress.getByName(ipaddress).getAddress();
...