Here you can find the source of isLocalOrLoopback(String address)
Parameter | Description |
---|---|
address | the address you which to check |
public static boolean isLocalOrLoopback(String address)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; public class Main { /**// ww w. j av a 2s. c om * 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; } }