Java Utililty Methods InetAddress Create

List of utility methods to do InetAddress Create

Description

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

Method

SetgetInetAddresses()
Get all Internet addresses of this computer.
return getInetAddresses(false);
ListgetInetAddresses(String filter)
get Inet Addresses
if (filter == null || (filter = filter.trim()).isEmpty())
    return getInetAddresses();
Pattern pat = Pattern.compile(filter.trim());
List<InetAddress> addresses = new ArrayList<InetAddress>();
for (InetAddress addr : getInetAddresses()) {
    if (pat.matcher(addr.toString().substring(1)).matches()) {
        addresses.add(addr);
return addresses;
Inet6AddressgetInetAddressFor(final Inet6Address inetAddress, String scope)
get Inet Address For
if (inetAddress.isLinkLocalAddress() || inetAddress.isSiteLocalAddress()) {
    final char[] chars = scope.toCharArray();
    boolean numeric = true;
    for (char c : chars) {
        if (!Character.isDigit(c)) {
            numeric = false;
            break;
    if (numeric) {
        return Inet6Address.getByAddress(null, inetAddress.getAddress(), Integer.parseInt(scope));
    } else {
        return Inet6Address.getByAddress(null, inetAddress.getAddress(), NetworkInterface.getByName(scope));
return inetAddress;
InetAddressgetInetAddressFromAsciiIP(String ip)
Given an ASCII format IP address string, return an InetAddress object.
String[] ipComponents = ip.split("\\.");
byte[] ipBytes = { (byte) Integer.parseInt(ipComponents[0]), (byte) Integer.parseInt(ipComponents[1]),
        (byte) Integer.parseInt(ipComponents[2]), (byte) Integer.parseInt(ipComponents[3])
};
return InetAddress.getByAddress(ipBytes);
InetAddressgetInetAddressFromConfigString(String fixedDeviceConfigSring)
Retrieve the InetAddress out of a fixedDeviceConfigSring.
String[] splitted = fixedDeviceConfigSring.split(FIXED_DEVICE_SET_CONFIG_STRING_SEPARATOR);
return InetAddress.getByName(splitted[0]);
InetAddressgetInetAddressFromString(String s)
get Inet Address From String
return InetAddress.getByName(s.replaceFirst(".*/", ""));
MapgetInetAddressMap()
get Inet Address Map
Map<InetAddress, String> found = new HashMap<>();
Enumeration<NetworkInterface> netInterfaces = null;
try {
    netInterfaces = NetworkInterface.getNetworkInterfaces();
    while (netInterfaces.hasMoreElements()) {
        NetworkInterface ni = netInterfaces.nextElement();
        Enumeration<InetAddress> address = ni.getInetAddresses();
        while (address.hasMoreElements()) {
...
MapgetInetAddressMap()
Method that returns a Map in which the key component of each element is one of the addresses of one of the network interface cards (nics) installed on the current node, and the corresponding value component is the name of the associated nic to which that address is assigned.
Map<InetAddress, String> retMap = new HashMap<InetAddress, String>();
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
while (nics.hasMoreElements()) {
    NetworkInterface curNic = nics.nextElement();
    Enumeration<InetAddress> curNicAddrs = curNic.getInetAddresses();
    String curNicName = curNic.getName();
    while (curNicAddrs.hasMoreElements()) {
        retMap.put(curNicAddrs.nextElement(), curNicName);
...
longgetInt32FromAddress(Inet4Address inetAddress)
get Int From Address
byte[] addrBytes = inetAddress.getAddress();
return ((long) convertByteToUnsigned(addrBytes[0]) << 24L)
        | ((long) convertByteToUnsigned(addrBytes[1]) << 16L)
        | ((long) convertByteToUnsigned(addrBytes[2]) << 8L) | (convertByteToUnsigned(addrBytes[3]));
NetworkInterfacegetInterface(InetAddress addr)
Return the Network Interface object that has the given InetAddress configured on it.
try {
    return NetworkInterface.getByInetAddress(addr);
} catch (Exception e) {
    return null;