Java Utililty Methods InetAddress Check

List of utility methods to do InetAddress Check

Description

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

Method

booleanisIPv6(InetAddress addr)
Checks the IP protocol version (IPv4 or IPv6)
return addr instanceof Inet6Address;
booleanisIPv6UniqueSiteLocal(InetAddress address)
is I Pv Unique Site Local
return (address.getAddress()[0] & 0xFF) == 0xFC
        || (address.getAddress()[0] & 0xFF) == 0xFD;
booleanisLikelyBroadcast(InetAddress address)
Checks whether the passed address is likely either a broadcast or network address
byte[] bytes = address.getAddress();
return bytes[bytes.length - 1] == 0 || bytes[bytes.length - 1] == (byte) 0xFF;
booleanisLinkLocalIPv4Address(InetAddress add)
Determines whether the address is an IPv4 link local address.
if (add instanceof Inet4Address) {
    byte address[] = add.getAddress();
    if ((address[0] & 0xFF) == 10)
        return true;
    if ((address[0] & 0xFF) == 172 && (address[1] & 0xFF) >= 16 && address[1] <= 31)
        return true;
    if ((address[0] & 0xFF) == 192 && (address[1] & 0xFF) == 168)
        return true;
...
booleanisLinkLocalNetwork(InetAddress addr)
is Link Local Network
byte[] bytes = addr.getAddress();
if (bytes.length != 4)
    return false;
if ((bytes[0] & 0xff) == 169 && (bytes[1] & 0xff) == 254)
    return true;
return false;
booleanisLocal(InetAddress a)
is Local
List<InetAddress> localIPs = getLocalIPs();
if (localIPs == null) {
    return false;
} else {
    return localIPs.contains(a);
booleanisLocalAddress(InetAddress addr)
Returns true if the given address represents the local host.
if (hasLocalScope(addr))
    return true;
Collection<NetworkInterface> nis = getNetworkInterfaces();
for (NetworkInterface ni : nis) {
    Enumeration<InetAddress> addresses = ni.getInetAddresses();
    while (addresses.hasMoreElements()) {
        if (addresses.nextElement().equals(addr))
            return true;
...
booleanisLocalAddress(InetAddress addr)
Given an InetAddress, checks to see if the address is a local address, by comparing the address with all the interfaces on the node.
boolean local = addr.isAnyLocalAddress() || addr.isLoopbackAddress();
if (!local) {
    try {
        local = NetworkInterface.getByInetAddress(addr) != null;
    } catch (SocketException e) {
return local;
...
booleanisLocalAddress(InetAddress addr)
is Local Address
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
    return true;
try {
    return NetworkInterface.getByInetAddress(addr) != null;
} catch (SocketException e) {
    return false;
booleanisLocalAddress(InetAddress address)
Checks if the given address is one of the addresses of the current machine.
NetworkInterface intf;
InetAddress addr;
Enumeration<InetAddress> eips = null;
Enumeration<NetworkInterface> eintfs = null;
try {
    eintfs = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e1) {
    e1.printStackTrace();
...