java.net.InetAddress
The Internet Protocol (IP) address class. This class encapsulates an IP
address and provides name and reverse name resolution functions. The address
is stored in network order, but as a signed (rather than unsigned) integer.
Known Direct Subclasses
Summary
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Methods
public
boolean
equals(Object obj)
Compares this
InetAddress
against the specified object.
Parameters
obj
| the object to be tested for equality |
Returns
- boolean true, if the objects are equal
public
byte[]
getAddress()
Returns the IP address of this
InetAddress
as an array.
The elements are in network order (the highest order address byte is in
the zero-th element).
Returns
- byte[] the address as a byte array
Answer the IP addresses of a named host. The host name may either be a
machine name or a dotted string IP address. If the host name is empty or
null, an UnknownHostException is thrown. If the host name is a dotted IP
string, an array with the corresponding single InetAddress is returned.
Parameters
host
| the hostName to be resolved to an address |
Returns
- InetAddress[] an array of addresses for the host
public
static
InetAddress
getByAddress(String hostName, byte[] ipAddress)
Returns the InetAddress corresponding to the array of bytes, and the
given hostname. In the case of an IPv4 address there must be exactly 4
bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is
thrown.
The host name and IP address are not validated.
The hostname either be a machine alias or a valid IPv6 or IPv4 address
format.
The high order byte is
ipAddress[0]
.
Parameters
hostName
| string representation of hostname or ip address |
ipAddress
| either a 4 (IPv4) or 16 (IPv6) byte array |
public
static
InetAddress
getByAddress(byte[] ipAddress)
Returns the InetAddress corresponding to the array of bytes. In the case
of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16
bytes. If not, an UnknownHostException is thrown.
The IP address is not validated by a name service.
The high order byte is
ipAddress[0]
.
Parameters
ipAddress
| either a 4 (IPv4) or 16 (IPv6) byte array |
Returns the address of a host, given a host string name. The host string
may be either a machine name or a dotted string IP address. If the
latter, the hostName field will be determined upon demand.
Parameters
host
| the hostName to be resolved to an address |
Returns
- InetAddress the InetAddress representing the host
public
String
getCanonicalHostName()
Returns canonical name for the host associated with the internet address
Returns
- String string containing the host name
public
String
getHostAddress()
Answer the dotted string IP address representing this address.
Returns
- String the corresponding dotted string IP address
public
String
getHostName()
Answer the host name.
Returns
- String the corresponding string name
public
static
InetAddress
getLocalHost()
Answer the local host, if allowed by the security policy. Otherwise,
answer the loopback address which allows this machine to be contacted.
Returns
- InetAddress the InetAddress representing the local host
public
int
hashCode()
Answer a hashcode for this IP address.
public
boolean
isAnyLocalAddress()
Method isAnyLocalAddress.
public
boolean
isLinkLocalAddress()
Returns true if the address is a link local address.
Valid IPv6 link local addresses are FE80::0 through to
FEBF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
There are no valid IPv4 link local addresses.
public
boolean
isLoopbackAddress()
Answer true if the address is a loop back address. Valid IPv4 loopback
addresses are 127.d.d.d Valid IPv6 loopback address is ::1
public
boolean
isMCGlobal()
Returns true if the address is a global multicast address.
Valid IPv6 link global multicast addresses are FFxE:/112 where x is a set
of flags, and the additional 112 bits make up the global multicast
address space
Valid IPv4 global multicast addresses are between: 224.0.1.0 to
238.255.255.255
public
boolean
isMCLinkLocal()
Returns true if the address is a link local multicast address.
Valid IPv6 link local multicast addresses are FFx2:/112 where x is a set
of flags, and the additional 112 bits make up the node local multicast
address space
Valid IPv4 link-local addresses are between: 224.0.0.0 to 224.0.0.255
public
boolean
isMCNodeLocal()
Returns true if the address is a node local multicast address.
Valid IPv6 node local multicast addresses are FFx1:/112 where x is a set
of flags, and the additional 112 bits make up the node local multicast
address space
There are no valid IPv4 node local multicast addresses.
public
boolean
isMCOrgLocal()
Returns true if the address is a organization local multicast address.
Valid IPv6 organization local multicast addresses are FFx8:/112 where x
is a set of flags, and the additional 112 bits make up the node local
multicast address space
Valid IPv4 organization-local addresses are between: 239.192.0.0 to
239.251.255.255
public
boolean
isMCSiteLocal()
Returns true if the address is a site local multicast address.
Valid IPv6 site local multicast addresses are FFx5:/112 where x is a set
of flags, and the additional 112 bits make up the node local multicast
address space
Valid IPv4 site-local addresses are between: 239.252.0.0 to
239.255.255.255
public
boolean
isMulticastAddress()
Answer true if the InetAddress is an IP multicast address.
Returns
- boolean true, if the address is in the multicast group
public
boolean
isReachable(int timeout)
Tries to see if the InetAddress is reachable. This method first tries to
use ICMP(ICMP ECHO REQUEST). When first step fails, the TCP connection on
port 7 (Echo) shall be lauched.
Parameters
timeout
| timeout in milliseconds |
Returns
- true if address is reachable
public
boolean
isReachable(NetworkInterface netif, int ttl, int timeout)
Tries to see if the InetAddress is reachable. This method first tries to
use ICMP(ICMP ECHO REQUEST). When first step fails, the TCP connection on
port 7 (Echo) shall be lauched.
Parameters
netif
| the network interface through which to connect |
ttl
| max hops to live |
timeout
| timeout in milliseconds |
Returns
- true if address is reachable
public
boolean
isSiteLocalAddress()
Returns true if the address is a site local address.
Valid IPv6 link local addresses are FEC0::0 through to
FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
There are no valid IPv4 site local addresses.
public
String
toString()
Returns a string containing a concise, human-readable description of the
address.
Returns
- String the description, as host/address