distance, upload and download options
Now user can limit output from --list parameter using --distance parameter (parameter can be used without --list parameter) Added support for testing only download or upload
This commit is contained in:
parent
7b09d8759f
commit
10d666daac
11
README.rst
11
README.rst
|
@ -74,7 +74,8 @@ Usage
|
||||||
::
|
::
|
||||||
|
|
||||||
$ speedtest-cli -h
|
$ speedtest-cli -h
|
||||||
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
|
usage: speedtest_cli.py [-h] [--bytes] [--share] [--simple] [--list]
|
||||||
|
[--distance DISTANCE] [--download] [--upload]
|
||||||
[--server SERVER] [--mini MINI] [--source SOURCE]
|
[--server SERVER] [--mini MINI] [--source SOURCE]
|
||||||
[--timeout TIMEOUT] [--secure] [--version]
|
[--timeout TIMEOUT] [--secure] [--version]
|
||||||
|
|
||||||
|
@ -84,13 +85,17 @@ Usage
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--bytes Display values in bytes instead of bits. Does not affect
|
--bytes Display values in bytes instead of bits. Does not
|
||||||
the image generated by --share
|
affect the image generated by --share
|
||||||
--share Generate and provide a URL to the speedtest.net share
|
--share Generate and provide a URL to the speedtest.net share
|
||||||
results image
|
results image
|
||||||
--simple Suppress verbose output, only show basic information
|
--simple Suppress verbose output, only show basic information
|
||||||
--list Display a list of speedtest.net servers sorted by
|
--list Display a list of speedtest.net servers sorted by
|
||||||
distance
|
distance
|
||||||
|
--distance DISTANCE Limit distance speedtest.net servers, list only closer
|
||||||
|
servers than specified
|
||||||
|
--download Test only download
|
||||||
|
--upload Test only upload
|
||||||
--server SERVER Specify a server ID to test against
|
--server SERVER Specify a server ID to test against
|
||||||
--mini MINI URL of the Speedtest Mini server
|
--mini MINI URL of the Speedtest Mini server
|
||||||
--source SOURCE Source IP address to bind to
|
--source SOURCE Source IP address to bind to
|
||||||
|
|
|
@ -582,6 +582,13 @@ def speedtest():
|
||||||
parser.add_argument('--list', action='store_true',
|
parser.add_argument('--list', action='store_true',
|
||||||
help='Display a list of speedtest.net servers '
|
help='Display a list of speedtest.net servers '
|
||||||
'sorted by distance')
|
'sorted by distance')
|
||||||
|
parser.add_argument('--distance',
|
||||||
|
help='Limit distance speedtest.net servers, '
|
||||||
|
'list only closer servers than specified')
|
||||||
|
parser.add_argument('--download', action='store_true',
|
||||||
|
help='Test only download')
|
||||||
|
parser.add_argument('--upload', action='store_true',
|
||||||
|
help='Test only upload')
|
||||||
parser.add_argument('--server', help='Specify a server ID to test against')
|
parser.add_argument('--server', help='Specify a server ID to test against')
|
||||||
parser.add_argument('--mini', help='URL of the Speedtest Mini server')
|
parser.add_argument('--mini', help='URL of the Speedtest Mini server')
|
||||||
parser.add_argument('--source', help='Source IP address to bind to')
|
parser.add_argument('--source', help='Source IP address to bind to')
|
||||||
|
@ -627,11 +634,13 @@ def speedtest():
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Retrieving speedtest.net server list...')
|
print_('Retrieving speedtest.net server list...')
|
||||||
if args.list or args.server:
|
if args.list or args.server or args.distance:
|
||||||
servers = closestServers(config['client'], True)
|
servers = closestServers(config['client'], True)
|
||||||
if args.list:
|
if args.list or args.distance:
|
||||||
serverList = []
|
serverList = []
|
||||||
for server in servers:
|
for server in servers:
|
||||||
|
if args.distance and server['d'] > int(args.distance):
|
||||||
|
break
|
||||||
line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) '
|
line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) '
|
||||||
'[%(d)0.2f km]' % server)
|
'[%(d)0.2f km]' % server)
|
||||||
serverList.append(line)
|
serverList.append(line)
|
||||||
|
@ -708,6 +717,7 @@ def speedtest():
|
||||||
else:
|
else:
|
||||||
print_('Ping: %(latency)s ms' % best)
|
print_('Ping: %(latency)s ms' % best)
|
||||||
|
|
||||||
|
if not args.upload or args.download:
|
||||||
sizes = [350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
|
sizes = [350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
|
||||||
urls = []
|
urls = []
|
||||||
for size in sizes:
|
for size in sizes:
|
||||||
|
@ -717,11 +727,15 @@ def speedtest():
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Testing download speed', end='')
|
print_('Testing download speed', end='')
|
||||||
dlspeed = downloadSpeed(urls, args.simple)
|
dlspeed = downloadSpeed(urls, args.simple)
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_()
|
print_()
|
||||||
print_('Download: %0.2f M%s/s' %
|
print_('Download: %0.2f M%s/s' %
|
||||||
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
else:
|
||||||
|
dlspeed = 0
|
||||||
|
|
||||||
|
if not args.download or args.upload:
|
||||||
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
|
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
|
||||||
sizes = []
|
sizes = []
|
||||||
for size in sizesizes:
|
for size in sizesizes:
|
||||||
|
@ -730,14 +744,20 @@ def speedtest():
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Testing upload speed', end='')
|
print_('Testing upload speed', end='')
|
||||||
ulspeed = uploadSpeed(best['url'], sizes, args.simple)
|
ulspeed = uploadSpeed(best['url'], sizes, args.simple)
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_()
|
print_()
|
||||||
print_('Upload: %0.2f M%s/s' %
|
print_('Upload: %0.2f M%s/s' %
|
||||||
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
else:
|
||||||
|
ulspeed = 0
|
||||||
|
|
||||||
if args.share and args.mini:
|
if args.share and args.mini:
|
||||||
print_('Cannot generate a speedtest.net share results image while '
|
print_('Cannot generate a speedtest.net share results image while '
|
||||||
'testing against a Speedtest Mini server')
|
'testing against a Speedtest Mini server')
|
||||||
|
elif args.share and (args.upload != args.download):
|
||||||
|
print_('Cannot generate a speedtest.net share results image while '
|
||||||
|
'testing only download or upload')
|
||||||
elif args.share:
|
elif args.share:
|
||||||
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
|
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
|
||||||
ping = int(round(best['latency'], 0))
|
ping = int(round(best['latency'], 0))
|
||||||
|
|
Loading…
Reference in New Issue