Java Local Address Check isLocalAddress(String host)

Here you can find the source of isLocalAddress(String host)

Description

is Local Address

License

Open Source License

Declaration

public static boolean isLocalAddress(String host) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static boolean isLocalAddress(String host) {
        try {//from   www . j  a v a2s  .  com
            InetAddress ia = InetAddress.getByName(host);

            if (ia.isAnyLocalAddress() || ia.isLoopbackAddress()) {
                return true;
            }

            return NetworkInterface.getByInetAddress(ia) != null;
        } catch (UnknownHostException | SocketException ex) {
            return false;
        }
    }
}

Related

  1. isLocalAddress(final String addr)
  2. isLocalAddress(final String address)
  3. isLocalAddress(String address)
  4. isLocalAddress(String address)
  5. isLocalAddress(String address)
  6. isLocalOrLoopback(String address)
  7. isLoopbackAddress(String address)
  8. isMyAddress(String host)