|
How to retrieve the IP address of a hostname |
|
|
This Java tip illustrates a method of identifying the IP address of a hostname. Developer
may use this code in client server or multi user applications where it is require to
know the IP Address of the client from where the request came.
try {
InetAddress addr = InetAddress.getByName("java-tips.org");
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) {
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.