Name

InetAddress

Synopsis

This class represents an Internet Protocol (IP) address. The class does not have a public constructor but instead supports static factory methods for obtaining InetAddress objects. getLocalHost( ) returns the InetAddress of the local computer. getByName( ) returns the InetAddress of a host specified by name. getAllByName( ) returns an array of InetAddress objects that represents all the available addresses for a host specified by name. getByAddress( ) returns an InetAddress that represents the IP address defined by the specified array of bytes.

Once you have obtained an InetAddress object, its instance methods provide various sorts of information about it. Two of the most important are getHostName( ) , which returns the hostname, and getAddress( ), which returns the IP address as an array of bytes, with the highest-order byte as the first element of the array. getHostAddress( ) returns the IP address formatted as a string rather than as an array of bytes. The various methods whose names begin with “is” determine whether the address falls into any of the named categories. The “isMC” methods are all related to multicast addresses.

This class was originally defined in Java 1.0, but many of its methods were added in Java 1.4. Java 1.4 also defined two subclasses, Inet4Address and Inet6Address representing IPv4 and IPv6 (version 4 and version 6) addresses. Java 5.0 adds isReachable( ) for testing whether the address describes a reachable (and responsive) ...

Get Java in a Nutshell, 5th Edition 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.