All Downloads are FREE. Search and download functionalities are using the official Maven repository.

automately.core.util.NetworkUtil Maven / Gradle / Ivy

package automately.core.util;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;

/**
 * NetworkUtil is a simple Utility that provides network utilities :)
 */
public class NetworkUtil {

    /**
     * This will check if a url or address is a loopback or local address
     * @param address the address you which to check
     * @return true if it is a loopback or local address
     */
    public static boolean isLocalOrLoopback(String address){
        try {
            try {
                URL url = new URL(address);
                address = url.getHost();
            } catch (MalformedURLException ignored) {
            }
            InetAddress inetAddress = InetAddress.getByName(address);
            return inetAddress.isAnyLocalAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isLoopbackAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return false;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy