Package org.xbill.DNS

Class Address

java.lang.Object
org.xbill.DNS.Address

public final class Address extends Object
Routines dealing with IP addresses. Includes functions similar to those in the java.net.InetAddress class.
Author:
Brian Wellington
  • Field Details

  • Method Details

    • toArray

      public static int[] toArray(String s, int family)
      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

      public static int[] toArray(String s)
      Convert a string containing an IPv4 address to an array of 4 integers.
      Parameters:
      s - The address, in text format.
      Returns:
      The address
    • toByteArray

      public static byte[] toByteArray(String s, int family)
      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

      public static boolean isDottedQuad(String s)
      Determines if a string contains a valid IP address.
      Parameters:
      s - The string
      Returns:
      Whether the string contains a valid IP address
    • toDottedQuad

      public static String toDottedQuad(byte[] addr)
      Converts a byte array containing an IPv4 address into a dotted quad string.
      Parameters:
      addr - The array
      Returns:
      The string representation
    • toDottedQuad

      public static String toDottedQuad(int[] addr)
      Converts an int array containing an IPv4 address into a dotted quad string.
      Parameters:
      addr - The array
      Returns:
      The string representation
    • getByName

      public static InetAddress getByName(String name) throws UnknownHostException
      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

      public static InetAddress[] getAllByName(String name) throws UnknownHostException
      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

      public static InetAddress getByAddress(String addr) throws UnknownHostException
      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

      public static InetAddress getByAddress(String addr, int family) throws UnknownHostException
      Converts an address from its string representation to an IP address in a particular family.
      Parameters:
      addr - The address, in string form
      family - 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

      public static String getHostName(InetAddress addr) throws UnknownHostException
      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

      public static int familyOf(InetAddress address)
      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

      public static InetAddress truncate(InetAddress address, int maskLength)
      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 address
      maskLength - The number of bits to truncate the address to.