Here you can find the source of isLocalhost(String host)
public static boolean isLocalhost(String host)
//package com.java2s; //License from project: Open Source License import java.net.*; public class Main { public static boolean isLocalhost(String host) { InetAddress address;/* w ww . j av a 2s . c o m*/ // convert the host name or ip string to an InetAddress object // If the address is unknown it is not localhost try { address = InetAddress.getByName(host); } catch (UnknownHostException e) { return false; } // Check if the address is a valid special local or loop back if (address.isAnyLocalAddress() || address.isLoopbackAddress()) return true; // Check if the address is defined on any interface try { return NetworkInterface.getByInetAddress(address) != null; } catch (SocketException e) { return false; } } }