public abstract class InetAddress extends Object implements Serializable
This class fulfills the function of the C style functions gethostname(), gethostbyname(), and gethostbyaddr(). It resolves Internet DNS names into their corresponding numeric addresses and vice versa.
Modifier and Type | Method and Description |
---|---|
protected static boolean |
equals(byte[] one,
byte[] two) |
boolean |
equals(Object obj)
Tests this address for equality against another InetAddress.
|
byte[] |
getAddress()
Returns the IP address of this object as a byte array.
|
static InetAddress[] |
getAllByName(String hostname)
Returns an array of InetAddress objects representing all the host/ip
addresses of a given host, given the host's name.
|
static InetAddress |
getByAddress(byte[] addr)
Returns an InetAddress object given the raw IP address.
|
static InetAddress |
getByAddress(String name,
byte[] addr)
Returns an InetAddress object given the raw IP address.
|
static InetAddress |
getByName(String hostname)
Returns an InetAddress object representing the IP address of the given
hostname.
|
String |
getHostAddress()
Returns the IP address of this object as a String.
|
String |
getHostName()
Returns the hostname for this address.
|
static InetAddress |
getLocalHost()
Returns an InetAddress object representing the address of the current
host.
|
int |
hashCode()
Returns a hash value for this address.
|
abstract boolean |
isAnyLocalAddress()
Checks if this address is a wildcard address
|
abstract boolean |
isLinkLocalAddress()
Checks if this address is a link local address
|
abstract boolean |
isMCGlobal()
Checks if this multicast address has global scope
|
abstract boolean |
isMCLinkLocal()
Checks if this multicast address has link scope
|
abstract boolean |
isMCNodeLocal()
Checks if this multicast address has node scope
|
abstract boolean |
isMCOrgLocal()
Checks if this multicast address has organization scope
|
abstract boolean |
isMCSiteLocal()
Checks if this multicast address has site scope
|
boolean |
isMulticastAddress()
Returns true if this address is a multicast address, false otherwise.
|
abstract boolean |
isSiteLocalAddress()
Checks if this address is a site local address
|
String |
toString()
Converts this address to a String.
|
public static InetAddress[] getAllByName(String hostname) throws UnknownHostException
hostname
- The name of the desired host, or null for the local machineUnknownHostException
- If no IP address can be found for the
given hostnamepublic static InetAddress getByName(String hostname) throws UnknownHostException
hostname
- The name of the desired host, or null for the local machineUnknownHostException
- If no IP address can be found for the
given hostnamepublic static InetAddress getLocalHost() throws UnknownHostException
UnknownHostException
- If an error occursprotected static boolean equals(byte[] one, byte[] two)
public boolean equals(Object obj)
public byte[] getAddress()
public String getHostAddress()
public String getHostName()
public int hashCode()
public boolean isMulticastAddress()
public String toString()
public static InetAddress getByAddress(String name, byte[] addr) throws UnknownHostException
name
- The host name.addr
- The IP address to create the InetAddress object from
The argument is in network byte order: the highest order byte of the
address is in getAddress()[0].UnknownHostException
- If IP address has illegal lengthpublic static InetAddress getByAddress(byte[] addr) throws UnknownHostException
addr
- The IP address to create the InetAddress object from
The argument is in network byte order: the highest order byte of the
address is in getAddress()[0].UnknownHostException
- If IP address has illegal lengthpublic abstract boolean isAnyLocalAddress()
public abstract boolean isLinkLocalAddress()
public abstract boolean isSiteLocalAddress()
public abstract boolean isMCGlobal()
public abstract boolean isMCNodeLocal()
public abstract boolean isMCLinkLocal()
public abstract boolean isMCSiteLocal()
public abstract boolean isMCOrgLocal()