public static void isValidInetAddress(String IP) throws IllegalArgumentException {
  if (IP == null || IP.isEmpty()) {
    throw new IllegalArgumentException("IP is missing or empty");
  }
  if (IP.contains(":")) {
  }
 else {
    String[] segments=IP.split("\\.");
    if (segments.length != 4) {
      throw new IllegalArgumentException("IP does not appear valid:" + IP);
    }
    try {
      InetAddress.getByName(IP);
    }
 catch (    UnknownHostException e) {
      throw new IllegalArgumentException(e);
    }
  }
}

public static void isValidInetAddress ( String IP ) throws IllegalArgumentException { if ( IP == null || IP . isEmpty ( ) ) { throw new IllegalArgumentException ( "IP is missing or empty" ) ; } if ( IP . contains ( ":" ) ) { } else { String [ ] segments = IP . split ( "\\." ) ; if ( segments . length != 4 ) { throw new IllegalArgumentException ( "IP does not appear valid:" + IP ) ; } try { InetAddress . getByName ( IP ) ; } catch ( UnknownHostException e ) { throw new IllegalArgumentException ( e ) ; } } }
verify if ip string is an ipv4 address .
