Added flags for testing only upload or only download speed

This commit is contained in:
Alexander Garden 2015-09-14 12:25:07 -04:00
parent 93951f1154
commit d016649e2a
3 changed files with 41 additions and 19 deletions

View File

@ -76,6 +76,7 @@ Usage
$ speedtest-cli -h
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
[--server SERVER] [--mini MINI] [--source SOURCE]
[--download] [--upload]
[--timeout TIMEOUT] [--secure] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
@ -94,6 +95,8 @@ Usage
--server SERVER Specify a server ID to test against
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--download Only test download speed
--upload Only test upload speed
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers

View File

@ -58,6 +58,16 @@ URL of the Speedtest Mini server
Source IP address to bind to
.RE
\fB\-\-download\fR
.RS
Only test download speed
.RE
\fB\-\-upload\fR
.RS
Only test upload speed
.RE
\fB\-\-version\fR
.RS
Show the version number and exit

View File

@ -590,6 +590,10 @@ def speedtest():
parser.add_argument('--secure', action='store_true',
help='Use HTTPS instead of HTTP when communicating '
'with speedtest.net operated servers')
parser.add_argument('--download', dest='downloadonly', action='store_true',
help='Only test download speed')
parser.add_argument('--upload', dest='uploadonly', action='store_true',
help='Only test upload speed')
parser.add_argument('--version', action='store_true',
help='Show the version number and exit')
@ -714,6 +718,7 @@ def speedtest():
for i in range(0, 4):
urls.append('%s/random%sx%s.jpg' %
(os.path.dirname(best['url']), size, size))
if not args.uploadonly:
if not args.simple:
print_('Testing download speed', end='')
dlspeed = downloadSpeed(urls, args.simple)
@ -722,6 +727,7 @@ def speedtest():
print_('Download: %0.2f M%s/s' %
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
if not args.downloadonly:
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
sizes = []
for size in sizesizes:
@ -738,6 +744,9 @@ def speedtest():
if args.share and args.mini:
print_('Cannot generate a speedtest.net share results image while '
'testing against a Speedtest Mini server')
elif args.share and (args.uploadonly or args.downloadonly):
print_('Cannot generate a speedtest.net share results image while '
'testing only upload or download speed')
elif args.share:
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
ping = int(round(best['latency'], 0))