Class InetAddress
java.net.InetAddress.
The platform exposes no resolver, which is a statement about the API rather than about DNS: DNS
is a protocol, and one of the ways to speak it is over HTTPS. So a name is resolved by asking a
DNS-over-HTTPS resolver with fetch, which suspends the fiber the way any other lookup does
and reads like an ordinary call.
getByName(java.lang.String) does not go over the network for an address written as one, nor for
localhost, so the common cases cost nothing. A resolved name is remembered for the life of
the isolate; the platform's own resolver caching is what decides how stale that can be, and a Worker
lives far too short a time for a TTL to be worth tracking.
Two limits. isReachable(int) sends an HTTPS request rather than an ICMP echo, because the
platform cannot send a datagram - so it reports whether a host answers HTTPS, which is a different
question and is documented as such rather than faked. And a lookup is a subrequest, so it counts
against the 50 the free plan allows per invocation.
What is not here, because nothing can back it: the local host's own address, a network interface, and a reverse lookup of a name from an address the resolver was not asked for.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbyte[]Returns the four or sixteen bytes of the address.static InetAddress[]getAllByName(String host) Every address of a host.static InetAddressgetByAddress(byte[] address) An address, without asking a resolver.static InetAddressgetByAddress(String host, byte[] address) An address for a host name, without asking a resolver.static InetAddressThe address of a host.Returns the same asgetHostName(), since no reverse lookup is made.Returns the address as text.Returns the name this address was resolved from, or the address when there was none.inthashCode()booleanReturns whether this is the unspecified address.booleanReturns whether this is a loopback address.booleanReturns whether this is a multicast address.booleanisReachable(int timeoutMillis) Whether the host answers an HTTPS request within a deadline.booleanReturns whether this is an address only reachable inside a private network.toString()
-
Method Details
-
getByName
The address of a host.- Parameters:
host- a host name, or an address written as one- Returns:
- the first address the resolver gave
- Throws:
UnknownHostException- when the resolver has no address for it
-
getAllByName
Every address of a host.- Parameters:
host- a host name, or an address written as one- Returns:
- the addresses, IPv4 before IPv6
- Throws:
UnknownHostException- when the resolver has no address for it
-
getByAddress
An address for a host name, without asking a resolver.- Parameters:
host- the name to report, or nulladdress- the four or sixteen bytes of the address- Returns:
- the address
- Throws:
UnknownHostException- when the length is neither four nor sixteen
-
getByAddress
An address, without asking a resolver.- Parameters:
address- the four or sixteen bytes of the address- Returns:
- the address
- Throws:
UnknownHostException- when the length is neither four nor sixteen
-
getHostAddress
Returns the address as text.- Returns:
- the address as text
-
getHostName
Returns the name this address was resolved from, or the address when there was none.- Returns:
- the name this address was resolved from, or the address when there was none
-
getCanonicalHostName
Returns the same asgetHostName(), since no reverse lookup is made.- Returns:
- the same as
getHostName(), since no reverse lookup is made
-
getAddress
public byte[] getAddress()Returns the four or sixteen bytes of the address.- Returns:
- the four or sixteen bytes of the address
-
isReachable
Whether the host answers an HTTPS request within a deadline.Not an ICMP echo, which the platform cannot send. A host that is up but serves no HTTPS reads as unreachable here.
- Parameters:
timeoutMillis- how long to allow, or zero for no limit- Returns:
- whether it answered
- Throws:
IOException- when the request could not be made at all
-
isLoopbackAddress
public boolean isLoopbackAddress()Returns whether this is a loopback address.- Returns:
- whether this is a loopback address
-
isSiteLocalAddress
public boolean isSiteLocalAddress()Returns whether this is an address only reachable inside a private network.- Returns:
- whether this is an address only reachable inside a private network
-
isMulticastAddress
public boolean isMulticastAddress()Returns whether this is a multicast address.- Returns:
- whether this is a multicast address
-
isAnyLocalAddress
public boolean isAnyLocalAddress()Returns whether this is the unspecified address.- Returns:
- whether this is the unspecified address
-
equals
-
hashCode
public int hashCode() -
toString
-