// be ready for IPv6
int num_bytes_in_an_IP_address = 4;
byte addr[] = new byte[num_bytes_in_an_IP_address];
StringTokenizer st = new StringTokenizer(s, ".");
// make sure the format is correct
if (st.countTokens() != addr.length) {
throw new UnknownHostException(s
+ " is not a valid numeric IP address");
}
for (int i = 0; i < addr.length; i++) {
int thisByte = Integer.parseInt(st.nextToken());
if (thisByte < 0 || thisByte > 255) {
throw new UnknownHostException(s
+ " is not a valid numeric IP address");
}
// check this
if (thisByte > 127) thisByte -= 256;
addr[i] = (byte) thisByte;
} // end for
return newInetAddress(addr);