The InetAddress class encapsulates both the IP address and the domain name for that address.

InetAddress can handle both IPv4 and IPv6 addresses.

The InetAddress class has no visible constructors. To create an InetAddress object, you use one of the available factory methods.

static InetAddress getLocalHost( ) throws UnknownHostException
returns the InetAddress object that represents the local host.
static InetAddress getByName(String hostName) throws UnknownHostException
returns an InetAddress for a host name passed to it.
static InetAddress[ ] getAllByName(String hostName) throws UnknownHostException
returns an array of InetAddresses that represent all of the addresses that a particular name resolves to.

Methods defined from InetAddress

getByAddress( ) takes an IP address and returns an InetAddress object. Either an IPv4 or an IPv6 address can be used.

boolean equals(Object other)
Returns true if this object has the same Internet address as other.
byte[ ] getAddress( )
Returns a byte array that represents the object's IP address in network byte order.
String getHostAddress( )
Returns a string that represents the host address associated with the InetAddress object.
String getHostName( )
Returns a string that represents the host name associated with the InetAddress object.
boolean isMulticastAddress( )
Returns true if this address is a multicast address. Otherwise, it returns false.
String toString( )
Returns a string that lists the host name and the IP address for convenience.

InetAddress has two subclasses: Inet4Address and Inet6Address.

  • Inet4Address represents a IPv4 address.
  • Inet6Address encapsulates a IPv6 address.
  Java Book 

  1. InetAddress
  2. InetAddress: getAllByName(String name)
  3. InetAddress: getByName(String host)
  4. InetAddress: getCanonicalHostName()
  5. InetAddress: getHostAddress()
  6. InetAddress: getHostName()
  7. InetAddress: getLocalHost()
  8. InetAddress: isReachable(int timeout)