public 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 |
---|---|
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 host,
byte[] addr)
Creates an InetAddress based on the provided host name and IP address.
|
static InetAddress |
getByLiteral(String literal)
Returns an InetAddress object representing the IP address of the given
literal IP address in dotted decimal format such as "127.0.0.1".
|
static InetAddress |
getByName(String hostname)
Returns an InetAddress object representing the IP address of the given
hostname.
|
String |
getCanonicalHostName()
Returns the canonical hostname represented by this InetAddress
|
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.
|
boolean |
isAnyLocalAddress()
Utility routine to check if the InetAddress in a wildcard address
|
boolean |
isLinkLocalAddress()
Utility routine to check if InetAddress is a link local address
|
boolean |
isLoopbackAddress()
Utility routine to check if the InetAddress is a loopback address
|
boolean |
isMCGlobal()
Utility routine to check if InetAddress is a global multicast address
|
boolean |
isMCLinkLocal()
Utility routine to check if InetAddress is a link local multicast address.
|
boolean |
isMCNodeLocal()
Utility routine to check if InetAddress is a node local multicast address.
|
boolean |
isMCOrgLocal()
Utility routine to check if InetAddress is a organization local multicast
address.
|
boolean |
isMCSiteLocal()
Utility routine to check if InetAddress is a site local multicast address.
|
boolean |
isMulticastAddress()
Returns true if this address is a multicast address, false otherwise.
|
boolean |
isSiteLocalAddress()
Utility routine to check if InetAddress is a site local address
|
String |
toString()
Converts this address to a String.
|
public boolean equals(Object obj)
public byte[] getAddress()
public static InetAddress[] getAllByName(String hostname) throws UnknownHostException
hostname
- The name of the desired host, or null for the local loopback
address.UnknownHostException
- If no IP address for the host could be foundpublic static InetAddress getByAddress(byte[] addr) throws UnknownHostException
addr
- The IP address to create the InetAddress object fromUnknownHostException
- If IP address has illegal lengthpublic static InetAddress getByAddress(String host, byte[] addr) throws UnknownHostException
host
- The hostname of the InetAddress object to createaddr
- The IP address to create the InetAddress object fromUnknownHostException
- If IP address is of illegal lengthpublic static InetAddress getByLiteral(String literal)
literal
- The literal IP address to create the InetAddress object frompublic static InetAddress getByName(String hostname) throws UnknownHostException
hostname
- The name of the desired host, or null for the local loopback
address.UnknownHostException
- If no IP address for the host could be foundpublic String getCanonicalHostName()
public String getHostAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public String getHostName()
public static InetAddress getLocalHost() throws UnknownHostException
UnknownHostException
- If no IP address for the host could be foundpublic int hashCode()
public boolean isAnyLocalAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isLinkLocalAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isLoopbackAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMCGlobal()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMCLinkLocal()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMCNodeLocal()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMCOrgLocal()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMCSiteLocal()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isMulticastAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.
public boolean isSiteLocalAddress()
This method cannot be abstract for backward compatibility reasons. By default
it always throws UnsupportedOperationException
unless overridden.