biz.neustar.wpm.api
Interface Dns


public interface Dns

Control the way DNS resolutions are done or make DNS resolutions directly. Here's a script to change the nameserver used for all DNS lookups:

 var dns = require('dns');

 // Use Google's nameserver instead of the agent's default nameserver.
 var nameserver = "8.8.8.8";
 dns.setNameServer(nameserver);

 var driver = test.openBrowser();

 test.beginTransaction();
 test.beginStep();

 test.get("www.yahoo.com");

 test.endStep();
 test.endTransaction();
 
And here's a script to do a DNS lookup directly and verify that a host name resolution is served up by UltraDNS:
 var dns = require('dns');

 var nameserver = "8.8.8.8";
 var host = "home.wpm.neustar.biz";
 var shouldMatch = /ultra/;
 var timeout = 2000;

 dns.setNameServer(nameserver);
 test.beginTransaction();
 test.beginStep();

 var r = dns.lookup("home.wpm.neustar.biz", "NS");

 var found = false;
 var records = r.getRecords();
 for (var i = 0; i < records.length; ++i) {
   var record = records[i];
   if (shouldMatch.test(record.getName())) {
     found = true;
   }
 }

 if (!found) {
   throw "Unable to verify nameserver for: " + host + " with regex: " + shouldMatch;
 }

 if (r.getQueryTime() < timeout) {
   throw "DNS request took too long: " + r.getQueryTime() + " > " + timeout + " milliseconds";
 }

 test.endStep();
 test.endTransaction();
 


Nested Class Summary
static interface Dns.DnsLookupResponse
           
static interface Dns.DnsRecord
           
 
Method Summary
 void clearCache()
          Flushes the DNS cache.
 boolean isCached(java.lang.String hostname)
          Returns true the if the given hostname is cached.
 Dns.DnsLookupResponse lookup(java.lang.String hostName)
          Lookup a hostname and report back its ips
 Dns.DnsLookupResponse lookup(java.lang.String hostName, java.lang.String recordType)
          Lookup a hostname and report back its ips.
 Dns.DnsLookupResponse lookupIp4(java.lang.String hostName)
          Lookup a hostname and report back its ipv4 ips
 Dns.DnsLookupResponse lookupIp6(java.lang.String hostName)
          Lookup a hostname and report back its ipv6 ips
 Dns.DnsLookupResponse lookupNS(java.lang.String hostName)
          Lookup a hostname and report back its ipv6 ips
 void remapHost(java.lang.String source, java.lang.String target)
          Provides functionality similar to editing your "hosts file" on your local computer.
 java.lang.String[] reverseLookup(java.lang.String ip)
          Reverse lookup an ip and report back its hostname(s).
 void setCacheTimeout(int timeoutMS)
          Sets the TTL for objects in the DNS cache in milliseconds.
 void setLookupMode(java.lang.String mode)
          Control the lookup priority of ipv4 vs ipv6.
 void setNameServer(java.lang.String nameServer1)
          Sets the DNS name server to use for all DNS lookups.
 void setNameServer(java.lang.String[] nameServers)
          Sets the DNS name server to use for all DNS lookups.
 void setTcp(boolean bUseTcp)
          Make DNS requests over TCP or switch back to using UDP.
 void setTimeout(int timeoutMS)
          Sets the timeout to use when making a request.
 

Method Detail

setNameServer

void setNameServer(java.lang.String nameServer1)
Sets the DNS name server to use for all DNS lookups.

Parameters:
nameServer1 - the primary name server

setNameServer

void setNameServer(java.lang.String[] nameServers)
Sets the DNS name server to use for all DNS lookups.

Parameters:
nameServers - the list of name servers

setLookupMode

void setLookupMode(java.lang.String mode)
Control the lookup priority of ipv4 vs ipv6. The available modes are: "ipv4" - Lookup addresses as ipv4 only "ipv6" - Lookup addresses as ipv6 only "ipv4-ipv6" - Lookup addresses first as ipv4 then ipv6 "ipv6-ipv4" - Lookup addresses first as ipv6 then ipv4

Parameters:
mode - the list of name servers

lookup

Dns.DnsLookupResponse lookup(java.lang.String hostName)
                             throws java.lang.Exception
Lookup a hostname and report back its ips

Parameters:
hostName - the hostname to lookup
Returns:
DNSLookupResponse with a list of ips to resolve to the hostname.
Throws:
java.lang.Exception - when the hostname cannot be resolved

lookup

Dns.DnsLookupResponse lookup(java.lang.String hostName,
                             java.lang.String recordType)
                             throws java.lang.Exception
Lookup a hostname and report back its ips. First lookup ipv4, then lookup ipv6 ips.

Parameters:
hostName - the hostname to lookup
recordType - the record type to lookup
Returns:
DNSLookupResponse with a list of ips to resolve to the hostname.
Throws:
java.lang.Exception - when the hostname cannot be resolved

lookupIp4

Dns.DnsLookupResponse lookupIp4(java.lang.String hostName)
                                throws java.lang.Exception
Lookup a hostname and report back its ipv4 ips

Parameters:
hostName - the hostname to lookup
Returns:
DNSLookupResponse with a list of ips to resolve to the hostname.
Throws:
java.lang.Exception - when the hostname cannot be resolved

lookupIp6

Dns.DnsLookupResponse lookupIp6(java.lang.String hostName)
                                throws java.lang.Exception
Lookup a hostname and report back its ipv6 ips

Parameters:
hostName - the hostname to lookup
Returns:
DNSLookupResponse with a list of ips to resolve to the hostname.
Throws:
java.lang.Exception - when the hostname cannot be resolved

lookupNS

Dns.DnsLookupResponse lookupNS(java.lang.String hostName)
                               throws java.lang.Exception
Lookup a hostname and report back its ipv6 ips

Parameters:
hostName - the hostname to lookup
Returns:
DNSLookupResponse with a list of authoritative name servers.
Throws:
java.lang.Exception - when the hostname cannot be resolved

reverseLookup

java.lang.String[] reverseLookup(java.lang.String ip)
                                 throws java.io.IOException
Reverse lookup an ip and report back its hostname(s).

Parameters:
ip - the ip to lookup a hostname for.
Returns:
list of hostnames for the given ip.
Throws:
java.io.IOException

clearCache

void clearCache()
Flushes the DNS cache.


setCacheTimeout

void setCacheTimeout(int timeoutMS)
Sets the TTL for objects in the DNS cache in milliseconds. Setting to -1 will cause hostnames to be cached for the length of the script. Setting to 0 will disable the cache altogether.

Parameters:
timeoutMS - timeout in milliseconds

isCached

boolean isCached(java.lang.String hostname)
Returns true the if the given hostname is cached.

Parameters:
hostname - the hostname to check
Returns:
true if the given hostname is cached

remapHost

void remapHost(java.lang.String source,
               java.lang.String target)
Provides functionality similar to editing your "hosts file" on your local computer. This can be used to map a domain to an IP address or alternative domain that isn't yet in the public DNS records. This is useful for testing websites that aren't yet public.

Parameters:
source - the source host to re-map from (i.e. www.example.com)
target - the target host to re-map to (i.e. new.example.com)

setTcp

void setTcp(boolean bUseTcp)
Make DNS requests over TCP or switch back to using UDP. Default is to use UDP.

Parameters:
bUseTcp - true if TCP, false use UDP

setTimeout

void setTimeout(int timeoutMS)
Sets the timeout to use when making a request.

Parameters:
timeoutMS - The time, in milliseconds, before the call aborts

Copyright © 2014 Neustar, Inc. All Rights Reserved.