Package org.xbill.DNS
Class Address
java.lang.Object
org.xbill.DNS.Address
Routines dealing with IP addresses. Includes functions similar to those in the
java.net.InetAddress class.
- Author:
- Brian Wellington
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intaddressLength(int family) Returns the length of an address in a particular family.static intfamilyOf(InetAddress address) Returns the family of an InetAddress.static InetAddress[]getAllByName(String name) Determines all IP address of a hoststatic InetAddressgetByAddress(String addr) Converts an address from its string representation to an IP address.static InetAddressgetByAddress(String addr, int family) Converts an address from its string representation to an IP address in a particular family.static InetAddressDetermines the IP address of a hoststatic StringgetHostName(InetAddress addr) Determines the hostname for an addressstatic booleanDetermines if a string contains a valid IP address.static int[]Convert a string containing an IPv4 address to an array of 4 integers.static int[]Convert a string containing an IP address to an array of 4 or 16 integers.static byte[]toByteArray(String s, int family) Convert a string containing an IP address to an array of 4 or 16 bytes.static StringtoDottedQuad(byte[] addr) Converts a byte array containing an IPv4 address into a dotted quad string.static StringtoDottedQuad(int[] addr) Converts an int array containing an IPv4 address into a dotted quad string.static InetAddresstruncate(InetAddress address, int maskLength) Truncates an address to the specified number of bits.
-
Field Details
-
IPv4
public static final int IPv4- See Also:
-
IPv6
public static final int IPv6- See Also:
-
-
Method Details
-
toArray
Convert a string containing an IP address to an array of 4 or 16 integers.- Parameters:
s- The address, in text format.family- The address family.- Returns:
- The address
-
toArray
Convert a string containing an IPv4 address to an array of 4 integers.- Parameters:
s- The address, in text format.- Returns:
- The address
-
toByteArray
Convert a string containing an IP address to an array of 4 or 16 bytes.- Parameters:
s- The address, in text format.family- The address family.- Returns:
- The address
-
isDottedQuad
Determines if a string contains a valid IP address.- Parameters:
s- The string- Returns:
- Whether the string contains a valid IP address
-
toDottedQuad
Converts a byte array containing an IPv4 address into a dotted quad string.- Parameters:
addr- The array- Returns:
- The string representation
-
toDottedQuad
Converts an int array containing an IPv4 address into a dotted quad string.- Parameters:
addr- The array- Returns:
- The string representation
-
getByName
Determines the IP address of a host- Parameters:
name- The hostname to look up- Returns:
- The first matching IP address
- Throws:
UnknownHostException- The hostname does not have any addresses
-
getAllByName
Determines all IP address of a host- Parameters:
name- The hostname to look up- Returns:
- All matching IP addresses
- Throws:
UnknownHostException- The hostname does not have any addresses
-
getByAddress
Converts an address from its string representation to an IP address. The address can be either IPv4 or IPv6.- Parameters:
addr- The address, in string form- Returns:
- The IP addresses
- Throws:
UnknownHostException- The address is not a valid IP address.
-
getByAddress
Converts an address from its string representation to an IP address in a particular family.- Parameters:
addr- The address, in string formfamily- The address family, either IPv4 or IPv6.- Returns:
- The IP addresses
- Throws:
UnknownHostException- The address is not a valid IP address in the specified address family.
-
getHostName
Determines the hostname for an address- Parameters:
addr- The address to look up- Returns:
- The associated host name
- Throws:
UnknownHostException- There is no hostname for the address
-
familyOf
Returns the family of an InetAddress.- Parameters:
address- The supplied address.- Returns:
- The family, either IPv4 or IPv6.
-
addressLength
public static int addressLength(int family) Returns the length of an address in a particular family.- Parameters:
family- The address family, either IPv4 or IPv6.- Returns:
- The length of addresses in that family.
-
truncate
Truncates an address to the specified number of bits. For example, truncating the address 10.1.2.3 to 8 bits would yield 10.0.0.0.- Parameters:
address- The source addressmaskLength- The number of bits to truncate the address to.
-