Java InetAddress Create getAddrInfo(InetAddress pAddr)

Here you can find the source of getAddrInfo(InetAddress pAddr)

Description

get Addr Info

License

Apache License

Declaration

private static String getAddrInfo(InetAddress pAddr) throws SocketException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;
import java.net.*;

public class Main {
    private static Method isUp;
    private static Method supportsMulticast;

    private static String getAddrInfo(InetAddress pAddr) throws SocketException {
        String ret = pAddr.getHostName() != null ? pAddr.getHostName() + " (" + pAddr.getHostAddress() + ")"
                : pAddr.getHostAddress();
        ret += " [site-local: " + pAddr.isSiteLocalAddress() + ", link-local: " + pAddr.isLinkLocalAddress()
                + ", lb: " + pAddr.isLoopbackAddress() + "]";
        NetworkInterface nif = NetworkInterface.getByInetAddress(pAddr);
        ret += " -- nif: " + getNetworkInterfaceInfo(nif);
        return ret;
    }/*from  ww w  .j av a2 s .c  o m*/

    private static String getNetworkInterfaceInfo(NetworkInterface pNif) throws SocketException {
        if (pNif == null) {
            return "[null]";
        }
        return pNif.getDisplayName() + " [up: " + pNif.isUp() + ", mc: " + pNif.supportsMulticast() + ", lb: "
                + pNif.isLoopback() + ", hw: " + formatHwAddress(pNif.getHardwareAddress()) + "]";
    }

    private static String formatHwAddress(byte[] pHardwareAddress) {
        if (pHardwareAddress == null) {
            return "[none]";
        }
        StringBuilder sb = new StringBuilder(18);
        for (byte b : pHardwareAddress) {
            if (sb.length() > 0) {
                sb.append(':');
            }
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
}

Related

  1. getActiveInterfaceInetAddresses()
  2. getAddressInfoFindAll(Function convertValue, Predicate doBreak)
  3. getAddressPriority(InetAddress addr)
  4. getAllInetAddress(final String interfaceName)
  5. getAllIPv4InetAddresses()
  6. getAllLocalIPv4InetAddresses()
  7. getBroadcast(InetAddress address)