Default to http, add --secure to specify use of https
This commit is contained in:
parent
3c04dfefd3
commit
075cfda9cf
|
@ -30,6 +30,8 @@ __version__ = '0.3.3a'
|
||||||
user_agent = 'speedtest-cli/%s' % __version__
|
user_agent = 'speedtest-cli/%s' % __version__
|
||||||
source = None
|
source = None
|
||||||
shutdown_event = None
|
shutdown_event = None
|
||||||
|
scheme = 'http'
|
||||||
|
|
||||||
|
|
||||||
# Used for bound_interface
|
# Used for bound_interface
|
||||||
socket_socket = socket.socket
|
socket_socket = socket.socket
|
||||||
|
@ -189,8 +191,13 @@ def build_request(url, data=None, headers={}):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if url[0] == ':':
|
||||||
|
schemed_url = '%s%s' % (scheme, url)
|
||||||
|
else:
|
||||||
|
schemed_url = url
|
||||||
|
|
||||||
headers['User-Agent'] = user_agent
|
headers['User-Agent'] = user_agent
|
||||||
return Request(url, data=data, headers=headers)
|
return Request(schemed_url, data=data, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
def catch_request(request):
|
def catch_request(request):
|
||||||
|
@ -349,7 +356,7 @@ def getConfig():
|
||||||
we are interested in
|
we are interested in
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request = build_request('http://www.speedtest.net/speedtest-config.php')
|
request = build_request('://www.speedtest.net/speedtest-config.php')
|
||||||
uh, e = catch_request(request)
|
uh, e = catch_request(request)
|
||||||
if e:
|
if e:
|
||||||
print_('Could not retrieve speedtest.net configuration: %s' % e)
|
print_('Could not retrieve speedtest.net configuration: %s' % e)
|
||||||
|
@ -391,8 +398,8 @@ def closestServers(client, all=False):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
urls = [
|
urls = [
|
||||||
'http://www.speedtest.net/speedtest-servers-static.php',
|
'://www.speedtest.net/speedtest-servers-static.php',
|
||||||
'http://c.speedtest.net/speedtest-servers-static.php',
|
'://c.speedtest.net/speedtest-servers-static.php',
|
||||||
]
|
]
|
||||||
errors = []
|
errors = []
|
||||||
servers = {}
|
servers = {}
|
||||||
|
@ -522,7 +529,7 @@ def version():
|
||||||
def speedtest():
|
def speedtest():
|
||||||
"""Run the full speedtest.net test"""
|
"""Run the full speedtest.net test"""
|
||||||
|
|
||||||
global shutdown_event, source
|
global shutdown_event, source, scheme
|
||||||
shutdown_event = threading.Event()
|
shutdown_event = threading.Event()
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, ctrl_c)
|
signal.signal(signal.SIGINT, ctrl_c)
|
||||||
|
@ -559,6 +566,9 @@ def speedtest():
|
||||||
parser.add_argument('--source', help='Source IP address to bind to')
|
parser.add_argument('--source', help='Source IP address to bind to')
|
||||||
parser.add_argument('--timeout', default=10, type=int,
|
parser.add_argument('--timeout', default=10, type=int,
|
||||||
help='HTTP timeout in seconds. Default 10')
|
help='HTTP timeout in seconds. Default 10')
|
||||||
|
parser.add_argument('--secure', action='store_true',
|
||||||
|
help='Use HTTPS instead of HTTP when communicating'
|
||||||
|
'with speedtest.net operated servers')
|
||||||
parser.add_argument('--version', action='store_true',
|
parser.add_argument('--version', action='store_true',
|
||||||
help='Show the version number and exit')
|
help='Show the version number and exit')
|
||||||
|
|
||||||
|
@ -580,6 +590,9 @@ def speedtest():
|
||||||
source = args.source
|
source = args.source
|
||||||
socket.socket = bound_socket
|
socket.socket = bound_socket
|
||||||
|
|
||||||
|
if args.secure:
|
||||||
|
scheme = 'https'
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Retrieving speedtest.net configuration...')
|
print_('Retrieving speedtest.net configuration...')
|
||||||
try:
|
try:
|
||||||
|
@ -739,8 +752,8 @@ def speedtest():
|
||||||
(ping, ulspeedk, dlspeedk, '297aae72'))
|
(ping, ulspeedk, dlspeedk, '297aae72'))
|
||||||
.encode()).hexdigest()]
|
.encode()).hexdigest()]
|
||||||
|
|
||||||
headers = {'Referer': 'https://c.speedtest.net/flash/speedtest.swf'}
|
headers = {'Referer': 'http://c.speedtest.net/flash/speedtest.swf'}
|
||||||
request = build_request('http://www.speedtest.net/api/api.php',
|
request = build_request('://www.speedtest.net/api/api.php',
|
||||||
data='&'.join(apiData).encode(),
|
data='&'.join(apiData).encode(),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
f, e = catch_request(request)
|
f, e = catch_request(request)
|
||||||
|
@ -761,8 +774,8 @@ def speedtest():
|
||||||
print_('Could not submit results to speedtest.net')
|
print_('Could not submit results to speedtest.net')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print_('Share results: https://www.speedtest.net/result/%s.png' %
|
print_('Share results: %s://www.speedtest.net/result/%s.png' %
|
||||||
resultid[0])
|
scheme, resultid[0])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue