- java.lang.Object
-
- com.aoapps.net.InetAddress
-
- All Implemented Interfaces:
DtoFactory<InetAddress>
,Internable<InetAddress>
,Serializable
,Comparable<InetAddress>
public final class InetAddress extends Object implements Comparable<InetAddress>, Serializable, DtoFactory<InetAddress>, Internable<InetAddress>
Represents either an IPv4 or an IPv6 IP address.The internal storage is always that of an IPv6 address. IPv4 addresses are stored as IPv4-mapped addresses (
::ffff:a.b.c.d
), but their external representation is always dotted-decimal IPv4 notation (a.b.c.d
).- Author:
- AO Industries, Inc.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static InetAddress
LOOPBACK_IPV4
static InetAddress
LOOPBACK_IPV6
static InetAddress
UNSPECIFIED_IPV4
static InetAddress
UNSPECIFIED_IPV6
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
compareTo(InetAddress other)
Sorts by address family then numeric address.boolean
equals(Object obj)
AddressFamily
getAddressFamily()
Deprecated.Please usegetProtocolFamily()
as of Java 1.7.AddressType
getAddressType()
Gets the type for this address.InetAddress
getDto()
long
getHigh()
Gets the high-order 64 bits of the numeric address.LongLong
getIp()
Gets the numeric address as a 128-bit integer.long
getLow()
Gets the low-order 64 bits of the numeric address.ProtocolFamily
getProtocolFamily()
int
hashCode()
InetAddress
intern()
Interns this IP much in the same fashion asString.intern()
.boolean
is6to4()
boolean
isBroadcast()
The IPv4 Broadcast (255.255.255.255/32
).boolean
isCarrierGradeNat()
boolean
isDocumentation()
boolean
isIPv4()
Deprecated.Please usegetProtocolFamily()
boolean
isIPv6()
Deprecated.Please usegetProtocolFamily()
boolean
isLinkLocal()
boolean
isLoopback()
boolean
isMulticast()
boolean
isNetworkBenchmark()
boolean
isOrchid()
boolean
isTeredo()
boolean
isUniqueLocal()
boolean
isUnspecified()
String
toBracketedString()
Gets an optionally-bracketed String representation of this IP address.String
toString()
Converts this IP address to its String representation.static ValidationResult
validate(String address)
Checks if the address is valid by callingparse(String)
and discarding the result.static InetAddress
valueOf(long hi, long lo)
Gets an IPv6 address from its numerical representation.static InetAddress
valueOf(LongLong ip)
Gets an IPv6 address from its numerical representation.static InetAddress
valueOf(String address)
Parses either an IPv4 or IPv6 address.
-
-
-
Field Detail
-
UNSPECIFIED_IPV4
public static final InetAddress UNSPECIFIED_IPV4
-
UNSPECIFIED_IPV6
public static final InetAddress UNSPECIFIED_IPV6
-
LOOPBACK_IPV4
public static final InetAddress LOOPBACK_IPV4
-
LOOPBACK_IPV6
public static final InetAddress LOOPBACK_IPV6
-
-
Method Detail
-
validate
public static ValidationResult validate(String address)
Checks if the address is valid by callingparse(String)
and discarding the result.When enclosed in brackets
"[...]"
, will be parsed as an IPv6InetAddress
(seetoBracketedString()
).- See Also:
parse(String)
-
valueOf
public static InetAddress valueOf(String address) throws ValidationException
Parses either an IPv4 or IPv6 address.When enclosed in brackets
"[...]"
, will be parsed as an IPv6InetAddress
(seetoBracketedString()
).- Parameters:
address
- whennull
, returnsnull
- Throws:
ValidationException
-
valueOf
public static InetAddress valueOf(LongLong ip)
Gets an IPv6 address from its numerical representation.- Parameters:
ip
- If ip is null, returns null.- See Also:
valueOf(long, long)
-
valueOf
public static InetAddress valueOf(long hi, long lo)
Gets an IPv6 address from its numerical representation.- See Also:
valueOf(com.aoapps.lang.math.LongLong)
-
compareTo
public int compareTo(InetAddress other)
Sorts by address family then numeric address.- Specified by:
compareTo
in interfaceComparable<InetAddress>
-
toString
public String toString()
Converts this IP address to its String representation.
-
toBracketedString
public String toBracketedString()
Gets an optionally-bracketed String representation of this IP address. If IPv6, the address is surrounded by [...]
-
intern
public InetAddress intern()
Interns this IP much in the same fashion asString.intern()
.- Specified by:
intern
in interfaceInternable<InetAddress>
- See Also:
String.intern()
-
getHigh
public long getHigh()
Gets the high-order 64 bits of the numeric address.
-
getLow
public long getLow()
Gets the low-order 64 bits of the numeric address.
-
getIp
public LongLong getIp()
Gets the numeric address as a 128-bit integer.
-
getDto
public InetAddress getDto()
- Specified by:
getDto
in interfaceDtoFactory<InetAddress>
-
isUnspecified
public boolean isUnspecified()
-
isLoopback
public boolean isLoopback()
- See Also:
LOOPBACK_IPV6
,InetAddressPrefixes.LOOPBACK_IPV4
-
isBroadcast
public boolean isBroadcast()
The IPv4 Broadcast (255.255.255.255/32
).See RFC 922, Section 7.
- See Also:
IPV4_BROADCAST_LO
-
isLinkLocal
public boolean isLinkLocal()
-
isMulticast
public boolean isMulticast()
-
isUniqueLocal
public boolean isUniqueLocal()
-
is6to4
public boolean is6to4()
-
isTeredo
public boolean isTeredo()
- See Also:
InetAddressPrefixes.TEREDO_IPV6
-
isDocumentation
public boolean isDocumentation()
-
isNetworkBenchmark
public boolean isNetworkBenchmark()
-
isOrchid
public boolean isOrchid()
- See Also:
InetAddressPrefixes.ORCHID_IPV6
-
isCarrierGradeNat
public boolean isCarrierGradeNat()
-
getAddressFamily
@Deprecated public AddressFamily getAddressFamily()
Deprecated.Please usegetProtocolFamily()
as of Java 1.7.
-
getProtocolFamily
public ProtocolFamily getProtocolFamily()
-
getAddressType
public AddressType getAddressType()
Gets the type for this address.
-
isIPv4
@Deprecated public boolean isIPv4()
Deprecated.Please usegetProtocolFamily()
-
isIPv6
@Deprecated public boolean isIPv6()
Deprecated.Please usegetProtocolFamily()
-
-