Java InetAddress Check isLocalAddress(InetAddress addr)

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

Description

is Local Address

License

Apache License

Declaration

static boolean isLocalAddress(InetAddress addr) 

Method Source Code

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

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;

public class Main {
    static boolean isLocalAddress(InetAddress addr) {
        // check if the address is a valid special local or loop back
        if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
            return true;

        // check if the address is defined on any interface
        try {/*from www  .jav  a  2  s.  c  o m*/
            return NetworkInterface.getByInetAddress(addr) != null;
        } catch (SocketException e) {
            return false;
        }
    }
}

Related

  1. isLinkLocalIPv4Address(InetAddress add)
  2. isLinkLocalNetwork(InetAddress addr)
  3. isLocal(InetAddress a)
  4. isLocalAddress(InetAddress addr)
  5. isLocalAddress(InetAddress addr)
  6. isLocalAddress(InetAddress address)
  7. isLocalAddress(InetAddress address)
  8. isLocalIP(final InetAddress ip1, final InetAddress ip2, final int mask)
  9. isLocalIpAddress(final InetAddress ipAddress)