Java Utililty Methods Local Address Check

List of utility methods to do Local Address Check

Description

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

Method

booleanisLocal(String brokerAddress)
return Whether the specified host:port corresponds to the local machine
String otherIP = getHost(getIPPort(brokerAddress));
InetAddress localHost;
try {
    localHost = InetAddress.getLocalHost();
    InetAddress inetAddresses[] = InetAddress.getAllByName(localHost.getHostName());
    for (int i = 0; i < inetAddresses.length; i++) {
        InetAddress thisInetAddr = inetAddresses[i];
        String thisIP = thisInetAddr.getHostAddress();
...
booleanisLocalAddress(final String addr)
is Local Address
try {
    return isLocalAddress(InetAddress.getByName(addr));
} catch (final Exception e) {
    return false;
booleanisLocalAddress(final String address)
is Local Address
final InetAddress inetAddress = InetAddress.getByName(address);
return inetAddress.isLinkLocalAddress() || inetAddress.isAnyLocalAddress()
        || inetAddress.isLoopbackAddress();
booleanisLocalAddress(String address)
Checks if the specified address is a private or loopback address
try {
    InetAddress inetAddress = InetAddress.getByName(address);
    return isLoopbackAddress(address)
            || inetAddress.isSiteLocalAddress()
            || inetAddress.isLinkLocalAddress()
            || isIPv6UniqueSiteLocal(inetAddress);
} catch (UnknownHostException e) {
    return false;
...
booleanisLocalAddress(String address)
Figure out if the address is local.
InetAddress targetAddress = InetAddress.getByName(address);
return getLocalAddresses().contains(targetAddress);
booleanisLocalAddress(String address)
is Local Address
if (address == null)
    return false;
return isLocalAddress(getByName(address));
booleanisLocalAddress(String host)
is Local Address
try {
    InetAddress ia = InetAddress.getByName(host);
    if (ia.isAnyLocalAddress() || ia.isLoopbackAddress()) {
        return true;
    return NetworkInterface.getByInetAddress(ia) != null;
} catch (UnknownHostException | SocketException ex) {
    return false;
...
booleanisLocalOrLoopback(String address)
This will check if a url or address is a loopback or local address
try {
    try {
        URL url = new URL(address);
        address = url.getHost();
    } catch (MalformedURLException ignored) {
    InetAddress inetAddress = InetAddress.getByName(address);
    return inetAddress.isAnyLocalAddress() || inetAddress.isLinkLocalAddress()
...
booleanisLoopbackAddress(String address)
Checks if the specified address is a loopback address.
try {
    InetAddress inetAddress = InetAddress.getByName(address);
    return inetAddress.isLoopbackAddress();
} catch (UnknownHostException e) {
    return false;
booleanisMyAddress(String host)
Determine whether the host name (or ip address) identifies the current machine.
if ("localhost".equals(host))
    return true;
boolean result = false;
try {
    final InetAddress addr = InetAddress.getByName(host);
    result = addr.isAnyLocalAddress() || addr.isLoopbackAddress();
    if (!result) {
        result = NetworkInterface.getByInetAddress(addr) != null;
...