8000 Add CDN ping time result to NameBench HTML report for better understanding the quality of the DNS server by rogers0 · Pull Request #2 · google/namebench · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Add CDN ping time result to NameBench HTML report for better understanding the quality of the DNS server #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions config/sanity_checks.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ version=4

[primary]
A a.root-servers.net.=198.41.0.4
A google.com.=74.125.,66.102.9.,66.102.11.,66.102.13.,66.102.7.,66.102.9.,209.85.1,209.85.22,209.85.231,64.233.16,64.233.17,64.233.18,66.249.8,66.249.9,72.14.2,216.239.3,216.239.4,216.239.5,216.239.6,150.101.98,210.8.185,173.194.33
A www.facebook.com.=69.63.17,69.63.18,69.63.190,69.63.191,66.220.14,66.220.15,www.facebook.com.edgesuite.net.,69.171.2
A www.google.com.=www.l.google.com.,www-tmmdi.l.google.com
A google.com.=74.125.,66.102.9.,66.102.11.,66.102.13.,66.102.7.,66.102.9.,209.85.1,209.85.22,209.85.231,64.233.16,64.233.17,64.233.18,66.249.8,66.249.9,72.14.2,216.239.3,216.239.4,216.239.5,216.239.6,150.101.98,210.8.185,173.194., # 216.239.32.0/19 64.233.160.0/19 66.249.80.0/20 72.14.192.0/18 209.85.128.0/17 66.102.0.0/20 74.125.0.0/16 64.18.0.0/20 207.126.144.0/20 173.194.0.0/16 # dig _netblocks.google.com txt
A www.google.com.=www.l.google.com.,74.125.,66.102.9.,66.102.11.,66.102.13.,66.102.7.,66.102.9.,209.85.1,209.85.22,209.85.231,64.233.16,64.233.17,64.233.18,66.249.8,66.249.9,72.14.2,216.239.3,216.239.4,216.239.5,216.239.6,150.101.98,210.8.185,173.194.,
A www.google-analytics.com.=www-google-analytics.l.google.com.
A static.ak.fbcdn.net.=static.ak.facebook.com.edgesuite.net.,a749.g.akamai.net.
A safebrowsing.clients.google.com.=clients.l.google.com.
A www.facebook.com.=star.c10r.facebook.com.
A static.ak.fbcdn.net.=static.ak.facebook.com.edgesuite.net.,a749.g.akamai.net.,a749.dsw4.akamai.net
A liveupdate.symantecliveupdate.com.=liveupdate.symantec.d4p.net.
A windowsupdate.microsoft.com.=windowsupdate.microsoft.nsatc.net.
A twitter.com.=168.143.162.,128.121.146.,128.121.243.,168.143.171.,168.143.161.,128.242.24,199.59.148
A twitter.com.=199.59.148.,199.59.149.,199.59.150.,199.59.151.

[secondary]
# The rest are run later
A www.paypal.com.=66.211.169.,64.4.241.
A www.paypal.com.=www.paypal.com.akadns.net.


[censorship]
Expand Down Expand Up @@ -63,3 +63,12 @@ A liberalthai.wordpress.com.=lb.wordpress.com.
A uddthailand.com.=74.52.22
A www.armtoday.info.=87.242.11
A www.aawsat.com.=83.244.20

[CDN]
A download.microsoft.com.=
A dl.google.com.=
A dl-ssl.google.com.=
A appldnld.apple.com.=
A www.facebook.com.=
A d36cz9buwru1tt.cloudfront.net.=
A cachefly.cachefly.net.=
19 changes: 11 additions & 8 deletions namebench.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@
10000 use_tk = True

if use_tk:
# Workaround for unicode path errors.
# See http://code.google.com/p/namebench/issues/detail?id=41
if hasattr(sys, 'winver') and hasattr(sys, 'frozen'):
os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tcl8.5')
os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tk8.5')
try:
# Workaround for unicode path errors.
# See http://code.google.com/p/namebench/issues/detail?id=41
if hasattr(sys, 'winver') and hasattr(sys, 'frozen'):
os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tcl8.5')
os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tk8.5')
import tkinter
except ImportError:
if len(sys.argv) == 1:
print("- The python-tk (tkinter) library is missing, using the command-line interface.\n")
use_tk = False
try:
import _tkinter
except ImportError:
if len(sys.argv) == 1:
print("- The python-tk (tkinter) library is missing, using the command-line interface.\n")
use_tk = False

if use_tk:
print('Starting graphical interface for namebench (use -x to force command-line usage)')
Expand Down
5 changes: 4 additions & 1 deletion namebench/client/better_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def open(url):
#
# If we are running on Windows, register the WindowsHttpDefault class.
if sys.platform[:3] == 'win':
import winreg
try:
import winreg
except ImportError:
import _winreg

# We don't want to load this class by default, because Python 2.4 doesn't have BaseBrowser.

Expand Down
33 changes: 1 addition & 32 deletions namebench/client/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@
# third_party dependencies
import httplib2

def GetFromGoogleLocAPI():
"""Use the Google Loc JSON API from Google Gears.

Returns:
A dictionary containing geolocation information

NOTE: This is in violation of the Gears Terms of Service. See:
http://code.google.com/p/gears/wiki/GeolocationAPI
"""
h = httplib2.Http(tempfile.gettempdir(), timeout=10)
url = 'http://www.google.com/loc/json'
post_data = {'request_address': 'true', 'version': '1.1.0', 'source': 'namebench'}
unused_resp, content = h.request(url, 'POST', json.dumps(post_data))
try:
data = json.loads(content)['location']
return {
'region_name': data['address'].get('region'),
'country_name': data['address'].get('country'),
'country_code': data['address'].get('country_code'),
'city': data['address'].get('city'),
'latitude': data['latitude'],
'longitude': data['longitude'],
'source': 'gloc'
}
except:
print(('* Failed to use GoogleLocAPI: %s (content: %s)' % (util.GetLastExceptionString(), content)))
return {}


def GetFromMaxmindJSAPI():
h = httplib2.Http(tempfile.gettempdir(), timeout=10)
unused_resp, content = h.request('http://j.maxmind.com/app/geoip.js', 'GET')
Expand All @@ -70,9 +41,7 @@ def GetFromMaxmindJSAPI():
def GetGeoData():
"""Get geodata from any means necessary. Sanitize as necessary."""
try:
json_data = GetFromGoogleLocAPI()
if not json_data:
json_data = GetFromMaxmindJSAPI()
json_data = GetFromMaxmindJSAPI()

# Make our data less accurate. We don't need any more than that.
json_data['latitude'] = '%.3f' % float(json_data['latitude'])
Expand Down
57 changes: 57 additions & 0 deletions namebench/client/health_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from . import util

from dns import rcode
import shell_ping

WILDCARD_DOMAINS = ('live.com.', 'blogspot.com.', 'wordpress.com.')
LIKELY_HIJACKS = ['www.google.com.', 'windowsupdate.microsoft.com.', 'www.paypal.com.']
Expand Down Expand Up @@ -107,6 +108,39 @@ def TestAnswers(self, record_type, record, expected, critical=False, timeout=Non

return (is_broken, error_msg, duration)

def TestCDNAnswers(self, record_type, record, timeout=None):
"""Test to see that an answer returns correct IP's.

Args:
record_type: text record type for NS query (A, CNAME, etc)
record: string to query for
timeout: timeout for query in seconds (int)

Returns:
(is_broken, error_msg, duration)
"""
is_broken = False
error_msg = ''
duration = -1
host = ''
if not timeout:
timeout = self.health_timeout
(response, duration, error_msg) = self.TimedRequest(record_type, record, timeout)
if response and not rcode.to_text(response.rcode()) in FATAL_RCODES and response.answer:
for answer in response.answer:
for rdata in answer:
if rdata.rdtype == 1:
host = str(rdata.address)
# ip, time_min, time_avg, time_max, lost
duration = shell_ping.ping(host, times=5)[1] # the min ping time among the results
break
if duration == -1:
is_broken = True
error_msg = '%s is failed to resolve' % record.rstrip('.')
else:
error_msg = '%dms ping time to CDN host %s(%s)' % (duration, record.rstrip('.'), host)
return (is_broken, error_msg, duration)

def TestBindVersion(self):
"""Test for BIND version. This acts as a pretty decent ping."""
_, duration = self.GetVersion()
Expand Down Expand Up @@ -225,6 +259,29 @@ def CheckCensorship(self, tests):
if warning:
self.AddWarning(warning, penalty=False)

def CheckCDN(self, tests):
"""Check the quality of CDN result from a nameserver."""
for (check, expected) in tests:
(req_type, req_name) = check.split(' ')
is_broken, warning, duration = self.TestCDNAnswers(req_type.upper(), req_name, timeout=CENSORSHIP_TIMEOUT)
if is_broken:
is_broken, warning, duration = self.TestCDNAnswers(req_type.upper(), req_name, timeout=CENSORSHIP_TIMEOUT)
if warning:
self.AddWarning(warning, penalty=False)
if is_broken:
self.is_disabled = True
self.cdn_ping_avg = 0
self.cdn_ping_min = 65535
self.cdn_ping_max = 0
self.AddWarning('Failed to ping CDN host %s, so removed from final comparison list.' % (req_name), penalty=False)
break
else:
self.cdn_ping_avg += duration
self.cdn_ping_min = min(self.cdn_ping_min, duration)
self.cdn_ping_max = max(self.cdn_ping_max, duration)
self.cdn_ping_avg /= float(len(tests))
return self.is_disabled

def CheckHealth(self, sanity_checks=None, fast_check=False, final_check=False, port_check=False):
"""Qualify a nameserver to see if it is any good."""

Expand Down
3 changes: 3 additions & 0 deletions namebench/client/nameserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def ResetTestStatus(self):
self.share_check_count = 0
self.cache_checks = []
self.is_slower_replica = False
self.cdn_ping_max = 0
self.cdn_ping_min = 65535
self.cdn_ping_avg = 0
self.ResetErrorCounts()

def ResetErrorCounts(self):
Expand Down
9 changes: 9 additions & 0 deletions namebench/client/nameserver_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def run(self):
self.results.put(ns.CheckHealth(sanity_checks=self.checks, port_check=True))
elif self.action_type == 'censorship':
self.results.put(ns.CheckCensorship(self.checks))
elif self.action_type == 'cdn':
self.results.put(ns.CheckCDN(self.checks))
elif self.action_type == 'store_wildcards':
self.results.put(ns.StoreWildcardCache())
elif self.action_type == 'node_id':
Expand Down Expand Up @@ -408,6 +410,8 @@ def CheckHealth(self, sanity_checks=None, max_servers=11, prefer_asn=None):
self.HideSlowSupplementalServers(max_servers)

self.RunFinalHealthCheckThreads(sanity_checks['secondary'])
#self.RunCensorshipCheckThreads(sanity_checks['censorship'])
self.RunCDNCheckThreads(sanity_checks['CDN'])
self.RunNodeIdThreads()
self.HideBrokenIPV6Servers()

Expand Down Expand Up @@ -649,6 +653,11 @@ def RunCensorshipCheckThreads(self, checks):
status_msg = 'Running censorship checks on %s servers' % len(self.enabled_servers)
return self._LaunchQueryThreads('censorship', status_msg, list(self.enabled_servers), checks=checks)

def RunCDNCheckThreads(self, checks):
"""Check ping time of CDN hostname."""
status_msg = 'Running CDN checks on %s servers' % len(self.enabled_servers)
return self._LaunchQueryThreads('cdn', status_msg, list(self.enabled_servers), checks=checks)

def RunPortBehaviorThreads(self):
"""Get port behavior data."""
status_msg = 'Running port behavior checks on %s servers' % len(self.enabled_servers)
Expand Down
7 changes: 5 additions & 2 deletions namebench/client/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _GenerateNameServerSummary(self):
}

# Fill the scores in.
for (ns, unused_avg, run_averages, fastest, slowest, unused_failures, nx_count, unused_total) in sorted_averages:
for (ns, overall_average, run_averages, fastest, slowest, unused_failures, nx_count, unused_total) in sorted_averages:
placed_at += 1

durations = []
Expand All @@ -325,7 +325,10 @@ def _GenerateNameServerSummary(self):

nsdata[ns].update({
'position': placed_at,
'overall_average': util.CalculateListAverage(run_averages),
'overall_average': overall_average,
'cdn_result_min': ns.cdn_ping_min,
'cdn_result_avg': ns.cdn_ping_avg,
'cdn_result_max': ns.cdn_ping_max,
'averages': run_averages,
'duration_min': float(fastest),
'duration_max': slowest,
Expand Down
2 changes: 1 addition & 1 deletion namebench/ui/base_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def GetExternalNetworkData(self):
domain = None
client_ip = providers.GetExternalIp()
if client_ip:
# self.UpdateStatus("Detected external IP as %s" % client_ip)
self.UpdateStatus("Detected external IP as %s" % client_ip)
local_ns = providers.SystemResolver()
hostname = local_ns.GetReverseIp(client_ip)
if hostname != client_ip:
Expand Down
Loading
0