Java Reference
In-Depth Information
InetAddress
declaresseveralclassmethodsforobtainingan
InetAddress
in-
stance. These methods include the following:
•
InetAddress[] getAllByName(String host)
returns an array
of
InetAddress
es that store the IP addresses associated with
host
. You
can pass either a domain name (e.g., "
tutortutor.ca
") or an IP address
(e.g.,"
70.33.247.10
")argumenttothisparameter.(CheckoutWikipedia's
“Domain name” entry [
http://en.wikipedia.org/wiki/Do-
InetAddress
instance that stores the IP address of the loopback interface
(defined shortly). This method throws
java.net.UnknownHostException
when no IP address for the speci-
fied
host
canbefound,orwhenascopeidentifierisspecifiedforaglobalIPv6
address.
•
InetAddress getByAddress(byte[] addr)
returns an
InetAd-
dress
object for the given raw IP address. The argument passed to
addr
is
in
network byte order
(mostsignificantbytefirst)wherethehighestorderbyte
is in
addr[0]
. The length of the
addr
array must be four bytes long for an
IPv4 address and sixteen bytes long for an IPv6 address. This method throws
UnknownHostException
when the array's length is neither 4 nor 16.
•
InetAddress getByAddress(String host, byte[] addr)
re-
turns an
InetAddress
instance based on the provided host name and IP
address. This method throws
UnknownHostException
when the array's
length is neither 4 nor 16.
•
InetAddress getByName(String host)
is equivalent to specifying
getAllByName(host)[0]
.
•
InetAddress getLocalHost()
returns the address of the
local host
(the current host), which is represented by hostname localhost or by an IP
address that is typically 127.0.0.1 [IPv4] or ::1 [IPv6)]. This method throws
UnknownHostException
when localhost couldn't be resolved into an ad-
dress.
•
InetAddress getLoopbackAddress()
returnsthe
loopback address
(a
specialIPaddressthatallowsnetwork-management softwaretotreatoutgoing
messages as incoming messages). The returned
InetAddress
instance rep-
resentstheIPv4loopbackaddress,127.0.0.1,ortheIPv6loopbackaddress,::1.
TheIPv4loopbackaddressreturnedisonlyoneofmanyintheform127.*.*.*,
where * is a wildcard that ranges from 0 through 255.