ValidityTools { public static boolean isLocalhost ( String host ) { try { InetAddress hostAddress = InetAddress.getByName( host ); if (hostAddress==null) return false; for ( InetAddress address : NETWORK_LOCAL_INETADDRESSES ) if ( address.equals( hostAddress ) ) return true; return hostAddress.isLoopbackAddress(); } catch ( UnknownHostException e ) { logger.debug( e.getMessage() ); return false; } }  static boolean isAccessibleSocket( String host , int port ); static boolean isAccessibleSocket( String host , int port, int timeOutInMSec ); static void checkAccessibilityOfDirs( String ... args ); static void checkAccessibilityOfFiles( String... args ); static void isDBAccessible( String driverClass , String url , String user , String password ); static String getHostName( String hostandport ); static int getPortNumber( String hostandport ); static boolean isLocalhost( String host ); static boolean isInt( String value ); static boolean isValidJavaVariable(CharSequence string); static final int SMTP_PORT; static final transient Logger logger; static final ArrayList < InetAddress > NETWORK_LOCAL_INETADDRESSES; }
@Test public void testIsLocalhost() { assertTrue(ValidityTools.isLocalhost("127.0.0.1")); assertFalse(ValidityTools.isLocalhost("127.0.1.1")); assertTrue(ValidityTools.isLocalhost("localhost")); assertFalse(ValidityTools.isLocalhost("129.0.0.1")); }