Java InetAddress Create getIPAsString(InetAddress addr)

Here you can find the source of getIPAsString(InetAddress addr)

Description

Returns a human readable IP address for the given address.

License

Open Source License

Parameter

Parameter Description
addr a parameter

Declaration

public static String getIPAsString(InetAddress addr) 

Method Source Code


//package com.java2s;
import java.net.InetAddress;

public class Main {
    /**//  w  w w  .  j  a  v  a 2 s. c  o  m
     * Returns a human readable IP address for the given address.
     * @param addr
     * @return
     */
    public static String getIPAsString(InetAddress addr) {
        byte[] ip = addr.getAddress();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ip.length; i++) {
            if (i != 0) {
                sb.append(".");
            }
            sb.append(ip[i] & 0xFF);
        }
        return sb.toString();
    }
}

Related

  1. getInterface(InetAddress addr)
  2. getIP(InetAddress ip)
  3. getIP(InetAddress ip)
  4. getIP(InetAddress ip)
  5. getIPAsLong(InetAddress address)
  6. getIPv4LocalNetMask(InetAddress ip, int netPrefix)
  7. getIPv6InetAddresses(NetworkInterface networkInterface)
  8. getLocalInetAddress()
  9. getLocalInetAddress()