public static boolean isDotQuadIP ( String hostname ) { if ( Character . isDigit ( hostname . charAt ( 0 ) ) ) { int i , len , dots ; char [ ] data ; i = dots = 0 ; /* quick IP address validation */ len = hostname . length ( ) ; data = hostname . toCharArray ( ) ; while ( i < len && Character . isDigit ( data [ i ++ ] ) ) { if ( i == len && dots == 3 ) { // probably an IP address return true ; } if ( i < len && data [ i ] == ' ' ) { dots ++ ; i ++ ; } } } return false ; }
Check whether a hostname is actually an ip address