org.jasen.util
Class DNSUtils

java.lang.Object
  extended byorg.jasen.util.DNSUtils

public final class DNSUtils
extends Object

General DNS utilities.

Author:
Jason Polites

Field Summary
static String[] TLD
          The current list of generic top level domains
This will be overwritten by a propertied file if one is found
 
Constructor Summary
DNSUtils()
           
 
Method Summary
static MXRecord[] getMXRecords(DNSResolver resolver, String canonical)
          Lists the MX records for the given canonical domain
static String getRootDomain(String domain)
          Gets the root domain from a fully qualified domain
Eg, gets microsoft.com from a.b.c.microsoft.com
static String getValidDomainOnly(String host)
          Gets the valid domain part of a URL.
static String invertIPAddress(String originalIPAddress)
          Inverts the IP address to match the requirements of DNS services.
static boolean isDomain(String str)
          Determines if the string passed "appears" to be a valid domain
static boolean isIPAddress(String address)
          Returns true if the given address is a valid IPv4 or IPv6 address
static boolean isIPv4Address(String address)
          Returns true if the given string is a correctly formed IPv4 address.
static boolean isIPv6Address(String address)
          Returns true if the given string is a correctly formed IPv6 address.
static void main(String[] args)
          Test harness only
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TLD

public static String[] TLD
The current list of generic top level domains
This will be overwritten by a propertied file if one is found

Constructor Detail

DNSUtils

public DNSUtils()
Method Detail

getMXRecords

public static MXRecord[] getMXRecords(DNSResolver resolver,
                                      String canonical)
                               throws UnknownHostException,
                                      DNSException
Lists the MX records for the given canonical domain

Parameters:
canonical - The canonical domain. Eg., microsoft.com, NOT www.microsoft.com
Returns:
The MX (mail exchanger) records for the given domain
Throws:
DNSException
UnknownHostException

isIPAddress

public static boolean isIPAddress(String address)
Returns true if the given address is a valid IPv4 or IPv6 address

Parameters:
address -
Returns:
True if the String passed is a valid IP address, false otherwise

isIPv4Address

public static boolean isIPv4Address(String address)
Returns true if the given string is a correctly formed IPv4 address.
The long regex stores each of the 4 numbers of the IP address into a capturing group.
Taken from: http://www.regular-expressions.info/examples.html

Parameters:
address -
Returns:
True if the String passed is a valid IP address, false otherwise

isIPv6Address

public static boolean isIPv6Address(String address)
Returns true if the given string is a correctly formed IPv6 address.
                        There are three conventional forms for representing IPv6 addresses as
                        text strings:

                        1. 	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.

                                Examples:

                                        FEDC:BA98:7654:3210:FEDC:BA98:7654:3210

                                        1080:0:0:0:8:800:200C:417A

                                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 2.).

                        2. 	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:

                                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:

                                        1080::8:800:200C:417A       a unicast address
                                        FF01::101                   a multicast address
                                        ::1                         the loopback address
                                        ::                          the unspecified addresses

                        3. 	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:

                                0:0:0:0:0:0:13.1.68.3

                                0:0:0:0:0:FFFF:129.144.52.38

                                or in compressed form:

                                ::13.1.68.3

                                ::FFFF:129.144.52.38

 

Parameters:
address -
Returns:
True if the String passed is a valid IP address, false otherwise
See Also:
http://www.ietf.org/rfc/rfc2373.txt

getRootDomain

public static String getRootDomain(String domain)
Gets the root domain from a fully qualified domain
Eg, gets microsoft.com from a.b.c.microsoft.com

Parameters:
domain -
Returns:

invertIPAddress

public static String invertIPAddress(String originalIPAddress)
Inverts the IP address to match the requirements of DNS services.

Parameters:
originalIPAddress - the IP address to invert
Returns:
the inverted form of the passed IP address

main

public static void main(String[] args)
Test harness only

Parameters:
args -

getValidDomainOnly

public static String getValidDomainOnly(String host)
Gets the valid domain part of a URL.

Parameters:
host -
Returns:
Returns null if there is no valid domain

isDomain

public static boolean isDomain(String str)
Determines if the string passed "appears" to be a valid domain

Parameters:
str - The string to test
Returns:
True if the string matches a standard domain sequence. That is, a sequence of alphanumeric characters delimited by dots. False otherwise