![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e144. Getting the IP Address of a Hostnametry { InetAddress addr = InetAddress.getByName("javaalmanac.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. |