Android Guides | Samples

Java.Net.InetAddress Class

An Internet Protocol (IP) address.

See Also: InetAddress

Syntax

[Android.Runtime.Register("java/net/InetAddress", DoNotGenerateAcw=true)]
public class InetAddress : Object, ISerializable, IDisposable

Remarks

An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in practice you'll have an instance of either Inet4Address or Inet6Address (this class cannot be instantiated directly). Most code does not need to distinguish between the two families, and should use InetAddress.

An InetAddress may have a hostname (accessible via getHostName), but may not, depending on how the InetAddress was created.

IPv4 numeric address formats

The getAllByName method accepts IPv4 addresses in the "decimal-dotted-quad" form only:

  • "1.2.3.4" - 1.2.3.4

IPv6 numeric address formats

The getAllByName method accepts IPv6 addresses in the following forms (this text comes from , which you should consult for full details of IPv6 addressing):

  • The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the hexadecimal values of the eight 16-bit pieces of the address. Note that it is not necessary to write the leading zeros in an individual field, but there must be at least one numeral in every field (except for the case described in the next bullet). Examples:

    java Example

         FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
         1080:0:0:0:8:800:200C:417A
  • Due to some methods of allocating certain styles of IPv6 addresses, it will be common for addresses to contain long strings of zero bits. In order to make writing addresses containing zero bits easier a special syntax is available to compress the zeros. The use of "::" indicates multiple groups of 16-bits of zeros. The "::" can only appear once in an address. The "::" can also be used to compress the leading and/or trailing zeros in an address. For example the following addresses:

    java Example

         1080:0:0:0:8:800:200C:417A  a unicast address
         FF01:0:0:0:0:0:0:101        a multicast address
         0:0:0:0:0:0:0:1             the loopback address
         0:0:0:0:0:0:0:0             the unspecified addresses
    may be represented as:

    java Example

         1080::8:800:200C:417A       a unicast address
         FF01::101                   a multicast address
         ::1                         the loopback address
         ::                          the unspecified addresses
  • An alternative form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values of the six high-order 16-bit pieces of the address, and the 'd's are the decimal values of the four low-order 8-bit pieces of the address (standard IPv4 representation). Examples:

    java Example

         0:0:0:0:0:0:13.1.68.3
         0:0:0:0:0:FFFF:129.144.52.38
    or in compressed form:

    java Example

         ::13.1.68.3
         ::FFFF:129.144.52.38

Scopes are given using a trailing % followed by the scope id, as in 1080::8:800:200C:417A%2 or 1080::8:800:200C:417A%en0. See for more on IPv6's scoped address architecture.

Additionally, for backwards compatibility, IPv6 addresses may be surrounded by square brackets.

DNS caching

In Android 4.0 (Ice Cream Sandwich) and earlier, DNS caching was performed both by InetAddress and by the C library, which meant that DNS TTLs could not be honored correctly. In later releases, caching is done solely by the C library and DNS TTLs are honored.

See Also

[Android Documentation]

Requirements

Namespace: Java.Net
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Net.InetAddress are listed below.

See Also: Object

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
CanonicalHostNameString. Returns the fully qualified hostname corresponding to this IP address.
[read-only]
HostAddressString. Returns the numeric representation of this IP address (such as "127.
[read-only]
HostNameString. Returns the host name corresponding to this IP address.
[read-only]
IsAnyLocalAddressBoolean. Returns whether this is the IPv6 unspecified wildcard address :: or the IPv4 "any" address, 0.0.0.0.
[read-only]
IsLinkLocalAddressBoolean. Returns whether this address is a link-local address or not.
[read-only]
IsLoopbackAddressBoolean. Returns whether this address is a loopback address or not.
[read-only]
IsMCGlobalBoolean. Returns whether this address is a global multicast address or not.
[read-only]
IsMCLinkLocalBoolean. Returns whether this address is a link-local multicast address or not.
[read-only]
IsMCNodeLocalBoolean. Returns whether this address is a node-local multicast address or not.
[read-only]
IsMCOrgLocalBoolean. Returns whether this address is a organization-local multicast address or not.
[read-only]
IsMCSiteLocalBoolean. Returns whether this address is a site-local multicast address or not.
[read-only]
IsMulticastAddressBoolean. Returns whether this address is a multicast address or not.
[read-only]
IsSiteLocalAddressBoolean. Returns whether this address is a site-local address or not.
[read-only]
static
LocalHostInetAddress. Returns an InetAddress for the local host if possible, or the loopback address otherwise.
[read-only]
static
LoopbackAddressInetAddress. Returns the IPv6 loopback address ::1 or the IPv4 loopback address 127.0.0.1.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

GetAddress() : Byte[]
Returns the IP address represented by this InetAddress instance as a byte array.
static
GetAllByName(String) : InetAddress[]
Gets all IP addresses associated with the given host identified by name or literal IP address.
static
GetByAddress(Byte[]) : InetAddress
Equivalent to getByAddress(null, ipAddress).
static
GetByAddress(String, Byte[]) : InetAddress
Returns an InetAddress corresponding to the given network-order bytes ipAddress and scopeId.
static
GetByName(String) : InetAddress
Returns the address of a host according to the given host string name host.
IsReachable(Int32) : Boolean
Tries to reach this InetAddress.
IsReachable(NetworkInterface, Int32, Int32) : Boolean
Tries to reach this InetAddress.