出处:http://www.apihome.cn/api/android/InetAddress.html
API之家,一个不错的API查询网站:http://www.apihome.cn/
java.net
类 InetAddress
java.lang.Object
java.net.InetAddress
-
所有已实现的接口:
- Serializable
-
直接已知子类:
- Inet4Address, Inet6Address
public class InetAddress extends Object implements Serializable
The Internet Protocol (IP) address representation 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.
-
从以下版本开始:
- Android 1.0 另请参见:
- 序列化表格
方法摘要 | |
---|---|
boolean | equals(Object obj) Compares this InetAddress instance against the specified address in obj . |
byte[] | getAddress() Returns the IP address represented by this InetAddress instance as a byte array. |
static InetAddress[] | getAllByName(String host) Gets all IP addresses associated with the given host identified by name or IP address in dot-notation. |
static InetAddress | getByAddress(byte[] ipAddress) Returns the InetAddress corresponding to the array of bytes. |
static InetAddress | getByAddress(String hostName, byte[] ipAddress) Returns the InetAddress corresponding to the array of bytes, and the given hostname. |
static InetAddress | getByName(String host) Returns the address of a host according to the given host string name host . |
String | getCanonicalHostName() Gets the fully qualified domain name for the host associated with this IP address. |
String | getHostAddress() Gets the textual representation of this IP address. |
String | getHostName() Gets the host name of this IP address. |
static InetAddress | getLocalHost() Gets the local host address if the security policy allows this. |
int | hashCode() Gets the hashcode of the represented IP address. |
boolean | isAnyLocalAddress() Returns whether this is a wildcard address or not. |
boolean | isLinkLocalAddress() Returns whether this address is a link-local address or not. |
boolean | isLoopbackAddress() Returns whether this address is a loopback address or not. |
boolean | isMCGlobal() Returns whether this address is a global multicast address or not. |
boolean | isMCLinkLocal() Returns whether this address is a link-local multicast address or not. |
boolean | isMCNodeLocal() Returns whether this address is a node-local multicast address or not. |
boolean | isMCOrgLocal() Returns whether this address is a organization-local multicast address or not. |
boolean | isMCSiteLocal() Returns whether this address is a site-local multicast address or not. |
boolean | isMulticastAddress() Returns whether this address is an IP multicast address or not. |
boolean | isReachable(int timeout) Tries to reach this InetAddress . |
boolean | isReachable(NetworkInterface netif, int ttl, int timeout) Tries to reach this InetAddress . |
boolean | isSiteLocalAddress() Returns whether this address is a site-local address or not. |
String | toString() Returns a string containing a concise, human-readable description of this IP address. |
从类 java.lang.Object 继承的方法 |
---|
getClass, notify, notifyAll, wait, wait, wait |
方法详细信息 |
---|
equals
public boolean equals(Object obj)
-
Compares this
InetAddress
instance against the specified address inobj
. Two addresses are equal if their address byte arrays have the same length and if the bytes in the arrays are equal. -
-
覆盖:
-
类
Object
中的equals
-
类
-
-
参数:
-
obj
- the object to be tested for equality.
返回:
-
true
if both objects are equal,false
otherwise.
从以下版本开始:
- Android 1.0 另请参见:
- Object.hashCode()
-
getAddress
public byte[] getAddress()
-
Returns the IP address represented by this
InetAddress
instance as a byte array. The elements are in network order (the highest order address byte is in the zeroth element). -
-
-
返回:
- the address in form of a byte array. 从以下版本开始:
- Android 1.0
getAllByName
public static InetAddress[] getAllByName(String host) throws UnknownHostException
-
Gets all IP addresses associated with the given
host
identified by name or IP address in dot-notation. The IP address is resolved by the configured name service. If the host name is empty ornull
anUnknownHostException
is thrown. If the host name is a dotted IP address string an array with the corresponding singleInetAddress
is returned. -
-
-
参数:
-
host
- the host's name or IP to be resolved to an address.
返回:
- the array of addresses associated with the specified host. 抛出:
-
UnknownHostException
- if the address lookup fails.
从以下版本开始:
- Android 1.0
-
getByName
public static InetAddress getByName(String host) throws UnknownHostException
-
Returns the address of a host according to the given host string name
host
. The host string may be either a machine name or a dotted string IP address. If the latter, thehostName
field is determined upon demand.host
can benull
which means that an address of the loopback interface is returned. -
-
-
参数:
-
host
- the hostName to be resolved to an address ornull
.
返回:
-
the
InetAddress
instance representing the host.
抛出:
-
UnknownHostException
- if the address lookup fails.
从以下版本开始:
- Android 1.0
-
getHostAddress
public String getHostAddress()
-
Gets the textual representation of this IP address.
-
-
-
返回:
- the textual representation of this host address in form of a dotted string. 从以下版本开始:
- Android 1.0
getHostName
public String getHostName()
-
Gets the host name of this IP address. If the IP address could not be resolved, the textual representation in a dotted-quad-notation is returned.
-
-
-
返回:
- the corresponding string name of this IP address. 从以下版本开始:
- Android 1.0
getCanonicalHostName
public String getCanonicalHostName()
-
Gets the fully qualified domain name for the host associated with this IP address. If a security manager is set, it is checked if the method caller is allowed to get the hostname. Otherwise, the textual representation in a dotted-quad-notation is returned.
-
-
-
返回:
- the fully qualified domain name of this IP address. 从以下版本开始:
- Android 1.0
getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
-
Gets the local host address if the security policy allows this. Otherwise, gets the loopback address which allows this machine to be contacted.
The current implementation returns always the loopback address.
-
-
-
返回:
-
the
InetAddress
representing the local host.
抛出:
-
UnknownHostException
- if the address lookup fails.
从以下版本开始:
- Android 1.0
-
the
hashCode
public int hashCode()
-
Gets the hashcode of the represented IP address.
-
-
覆盖:
-
类
Object
中的hashCode
-
类
-
-
返回:
- the appropriate hashcode value. 从以下版本开始:
- Android 1.0 另请参见:
- Object.equals(java.lang.Object)
isMulticastAddress
public boolean isMulticastAddress()
-
Returns whether this address is an IP multicast address or not.
-
-
-
返回:
-
true
if this address is in the multicast group,false
otherwise.
从以下版本开始:
- Android 1.0
-
toString
public String toString()
-
Returns a string containing a concise, human-readable description of this IP address.
-
-
覆盖:
-
类
Object
中的toString
-
类
-
-
返回:
- the description, as host/address. 从以下版本开始:
- Android 1.0
isLoopbackAddress
public boolean isLoopbackAddress()
-
Returns whether this address is a loopback address or not. This implementation returns always
false
. Valid IPv4 loopback addresses are 127.d.d.d The only valid IPv6 loopback address is ::1. -
-
-
返回:
-
true
if this instance represents a loopback address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isLinkLocalAddress
public boolean isLinkLocalAddress()
-
Returns whether this address is a link-local address or not. This implementation returns always
false
.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.
-
-
-
返回:
-
true
if this instance represents a link-local address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isSiteLocalAddress
public boolean isSiteLocalAddress()
-
Returns whether this address is a site-local address or not. This implementation returns always
false
.Valid IPv6 site-local addresses are FEC0::0 through to FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF.
There are no valid IPv4 site-local addresses.
-
-
-
返回:
-
true
if this instance represents a site-local address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isMCGlobal
public boolean isMCGlobal()
-
Returns whether this address is a global multicast address or not. This implementation returns always
false
.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.
-
-
-
返回:
-
true
if this instance represents a global multicast address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isMCNodeLocal
public boolean isMCNodeLocal()
-
Returns whether this address is a node-local multicast address or not. This implementation returns always
false
.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.
-
-
-
返回:
-
true
if this instance represents a node-local multicast address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isMCLinkLocal
public boolean isMCLinkLocal()
-
Returns whether this address is a link-local multicast address or not. This implementation returns always
false
.Valid IPv6 link-local multicast addresses are FFx2:/112 where x is a set of flags, and the additional 112 bits make up the link-local multicast address space.
Valid IPv4 link-local addresses are between: 224.0.0.0 to 224.0.0.255
-
-
-
返回:
-
true
if this instance represents a link-local multicast address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isMCSiteLocal
public boolean isMCSiteLocal()
-
Returns whether this address is a site-local multicast address or not. This implementation returns always
false
.Valid IPv6 site-local multicast addresses are FFx5:/112 where x is a set of flags, and the additional 112 bits make up the site-local multicast address space.
Valid IPv4 site-local addresses are between: 239.252.0.0 to 239.255.255.255
-
-
-
返回:
-
true
if this instance represents a site-local multicast address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isMCOrgLocal
public boolean isMCOrgLocal()
-
Returns whether this address is a organization-local multicast address or not. This implementation returns always
false
.Valid IPv6 organization-local multicast addresses are FFx8:/112 where x is a set of flags, and the additional 112 bits make up the organization-local multicast address space.
Valid IPv4 organization-local addresses are between: 239.192.0.0 to 239.251.255.255
-
-
-
返回:
-
true
if this instance represents a organization-local multicast address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isAnyLocalAddress
public boolean isAnyLocalAddress()
-
Returns whether this is a wildcard address or not. This implementation returns always
false
. -
-
-
返回:
-
true
if this instance represents a wildcard address,false
otherwise.
从以下版本开始:
- Android 1.0
-
isReachable
public boolean isReachable(int timeout) throws IOException
-
Tries to reach this
InetAddress
. This method first tries to use ICMP (ICMP ECHO REQUEST). When first step fails, a TCP connection on port 7 (Echo) of the remote host is established. -
-
-
参数:
-
timeout
- timeout in milliseconds before the test fails if no connection could be established.
返回:
-
true
if this address is reachable,false
otherwise.
抛出:
-
IOException
- if an error occurs during an I/O operation. -
IllegalArgumentException
- if timeout is less than zero.
从以下版本开始:
- Android 1.0
-
isReachable
public boolean isReachable(NetworkInterface netif, int ttl, int timeout) throws IOException
-
Tries to reach this
InetAddress
. This method first tries to use ICMP (ICMP ECHO REQUEST). When first step fails, a TCP connection on port 7 (Echo) of the remote host is established. -
-
-
参数:
-
netif
- the network interface on which to connection should be established. -
ttl
- the maximum count of hops (time-to-live). -
timeout
- timeout in milliseconds before the test fails if no connection could be established.
返回:
-
true
if this address is reachable,false
otherwise.
抛出:
-
IOException
- if an error occurs during an I/O operation. -
IllegalArgumentException
- if ttl or timeout is less than zero.
从以下版本开始:
- Android 1.0
-
getByAddress
public static InetAddress getByAddress(byte[] ipAddress) throws UnknownHostException
-
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, anUnknownHostException
is thrown.The IP address is not validated by a name service.
The high order byte is
ipAddress[0]
. -
-
-
参数:
-
ipAddress
- is either a 4 (IPv4) or 16 (IPv6) byte long array.
返回:
-
an
InetAddress
instance representing the given IP addressipAddress
.
抛出:
-
UnknownHostException
- if the given byte array has no valid length.
从以下版本开始:
- Android 1.0
-
getByAddress
public static InetAddress getByAddress(String hostName, byte[] ipAddress) throws UnknownHostException
-
Returns the
InetAddress
corresponding to the array of bytes, andthe given hostname. In the case of an IPv4 address there must be exactly4 bytes and for IPv6 exactly 16 bytes. If not, anUnknownHostException
will be thrown.The host name and IP address are not validated.
The hostname either be a machine alias or a valid IPv6 or IPv4 addressformat.
The high order byte is
ipAddress[0]
. -
-
-
参数:
-
hostName
- the string representation of hostname or IP address. -
ipAddress
- either a 4 (IPv4) or 16 (IPv6) byte long array.
返回:
-
an
InetAddress
instance representing the given IP addressand hostname.
抛出:
-
UnknownHostException
- if the given byte array has no valid length.
从以下版本开始:
- Android 1.0
-