def testMinimumDurationBarGraph(self): fastest = ((nameserver.NameServer('208.67.220.220', name='OpenDNS'), 10.0), (nameserver.NameServer('156.154.70.1', name='UltraDNS'), 15.75)) expected = ( 'http://chart.apis.google.com/chart?chxt=y%2Cx%2Cx&chd=e%3AgAyZ&' 'chxp=2%2C9&chxr=1%2C0%2C20%7C2%2C-1.0%2C21.0&chxtc=1%2C-720' '&chco=0000ff&chbh=a&chs=720x78&cht=bhg&chxl=0%3A%7CUltraDNS%7COpenDNS' '%7C1%3A%7C0%7C3%7C6%7C9%7C12%7C15%7C18%7C20%7C2%3A%7C' 'Duration%20in%20ms.') self.assertEquals(charts.MinimumDurationBarGraph(fastest), expected)
def _ExampleRunsData(): odns = nameserver.NameServer('208.67.220.220', name='OpenDNS') udns = nameserver.NameServer('156.154.70.1', name='UltraDNS') data = [(odns, [ 79.0, 191.0, 84.0, 878.0, 82.0, 85.0, 882.0, 187.0, 79.0, 80.0, 79.0, 261.0, 79.0, 83.0, 82.0, 420.0, 822.0, 1890.0, 78.0, 79.0, 86.0, 89.0, 125.0, 94.0, 81.0, 79.0, 81.0, 79.0, 1105.0, 84.0 ]), (udns, [ 9.0, 8.0, 13.0, 329.0, 9.0, 9.0, 773.0, 52.0, 9.0, 8.0, 8.0, 143.0, 27.0, 104.0, 8.0, 8.0, 320.0, 594.0, 8.0, 312.0, 11.0, 9.0, 174.0, 83.0, 8.0, 9.0, 8.0, 8.0, 496.0, 533.0 ])] return data
def GetNameServerData(filename='config/servers.csv'): server_file = util.FindDataFile(filename) ns_data = _ParseNameServerListing(open(server_file)) # Add the system servers for later reference. for i, ip in enumerate(sys_nameservers.GetCurrentNameServers()): ns = nameserver.NameServer(ip, name='SYS%s-%s' % (i, ip), system_position=i) ns_data.append(ns) for i, ip in enumerate(sys_nameservers.GetAssignedNameServers()): ns = nameserver.NameServer(ip, name='DHCP%s-%s' % (i, ip), dhcp_position=i) ns_data.append(ns) return ns_data
def GatherNameServerData(self): """Build a nameserver data set from config and other sources.""" ns_data = config.GetNameServerData() for i, ip in enumerate(self.options.servers): ns = nameserver.NameServer(ip, tags=['specified'], name='USR%s-%s' % (i, ip)) ns_data.append(ns) return ns_data
def GetSystemPrimaryNameServer(self): """Return a nameserver object for the system primary.""" internal = nameserver_list.InternalNameServers() # In rare cases, we may not find any to use. if not internal: print 'Odd - no built-in nameservers found.' return None else: primary_ip = internal[0] return nameserver.NameServer(primary_ip)
def GetInterceptionStatus(self): """Check if our packets are actually getting to the correct servers.""" opendns = nameserver.NameServer(OPENDNS_NS) (node_id, duration, unused_error) = opendns.RequestNodeId() if 'I am not an OpenDNS resolver' in node_id: return (True, duration) elif node_id: return (False, duration) else: self.msg('DNS interception test failed (no response)') return (False, duration) return (False, duration)
def _ParseNameServerListing(fp): fields = [ 'ip', 'tags', 'provider', 'instance', 'hostname', 'location', 'coords', 'asn', 'list_note', 'urls' ] reader = csv.DictReader(fp, fieldnames=fields) ns_data = nameserver_list.NameServers() for row in reader: if row['instance']: name = "%s (%s)" % (row['provider'], row['instance']) else: name = row['provider'] if row['coords']: lat, lon = row['coords'].split(',') else: lat = lon = None as_match = re.match('AS(\d+)(.*)', row['asn']) if as_match: asn, network_owner = as_match.groups() network_owner = network_owner.lstrip(' ').rstrip(' ') else: asn = network_owner = None ns_data.append( nameserver.NameServer(row['ip'], name=name, tags=row['tags'].split(), provider=row['provider'], instance=row['instance'], location=row['location'], latitude=lat, longitude=lon, asn=asn, hostname=row['hostname'], network_owner=network_owner)) return ns_data
def AddServer(self, ip, name, is_preferred=False, is_global=False, is_regional=False, is_custom=False): """Add a server to the list given an IP and name.""" ns = nameserver.NameServer(ip, name=name, preferred=is_preferred) if self.ipv6_only and not ns.is_ipv6: return ns.is_custom = is_custom if ip in self.system_nameservers: ns.is_system = True ns.is_preferred = True ns.is_custom = False ns.system_position = self.system_nameservers.index(ip) ns.is_global = is_global ns.is_regional = is_regional ns.timeout = self.timeout ns.ping_timeout = self.ping_timeout # Give them a little extra love for the road. if ns.is_system: ns.health_timeout = self.health_timeout * SYSTEM_HEALTH_TIMEOUT_MULTIPLIER ns.ping_timeout = self.ping_timeout * SYSTEM_HEALTH_TIMEOUT_MULTIPLIER elif ns.is_preferred: ns.health_timeout = self.health_timeout * PREFERRED_HEALTH_TIMEOUT_MULTIPLIER ns.ping_timeout = self.ping_timeout * PREFERRED_HEALTH_TIMEOUT_MULTIPLIER else: ns.health_timeout = self.health_timeout self.append(ns)
def GetGoogleResponseDuration(self): """See how quickly we can query for www.google.com using a remote nameserver.""" gdns = nameserver.NameServer(GOOGLE_NS) return gdns.TimedRequest('A', 'www.google.com.')