![]() |
The Java Developers Almanac 1.4 |
|
e144. Getting the IP Address of a Hostname try {
InetAddress addr = InetAddress.getByName("exampledepot.com");
byte[] ipAddr = addr.getAddress();
// Convert to dot representation
String ipAddrStr = "";
for (int i=0; i<ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i]&0xFF;
}
} catch (UnknownHostException e) {
}
e146. Getting the IP Address and Hostname of the Local Machine
© 2002 Addison-Wesley. |