Working with Host Names and IP Addresses

The class java.net.InetAddress provides support for getting host names with IP addresses or getting IP addresses using host names. Listing 14.1 shows a program that uses several of these methods.

Host Information Using INetAddress: Code Example

The INetAddress class exists to allow a program to find out IP addresses based on host names and host names based on IP addresses. The INetAddress class also provides a mechanism to identify the current host on which the program is running, which can be quite helpful in many situations that call for an IP address or INetAddress object.

Code Listing 14.1. Getting Host IP Information Using the INetAddress Class (NetDriver1.java)
 import java.io.*; import java.net.*; ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.