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 $ speedtest-cli -h
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list] usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
[--server SERVER] [--mini MINI] [--source SOURCE] [--server SERVER] [--mini MINI] [--source SOURCE]
[--download] [--upload]
[--timeout TIMEOUT] [--secure] [--version] [--timeout TIMEOUT] [--secure] [--version]
Command line interface for testing internet bandwidth using speedtest.net. Command line interface for testing internet bandwidth using speedtest.net.
@ -94,6 +95,8 @@ Usage
--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
--download Only test download speed
--upload Only test upload speed
--timeout TIMEOUT HTTP timeout in seconds. Default 10 --timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with --secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers speedtest.net operated servers

View File

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

View File

@ -590,6 +590,10 @@ def speedtest():
parser.add_argument('--secure', action='store_true', parser.add_argument('--secure', action='store_true',
help='Use HTTPS instead of HTTP when communicating ' help='Use HTTPS instead of HTTP when communicating '
'with speedtest.net operated servers') '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', parser.add_argument('--version', action='store_true',
help='Show the version number and exit') help='Show the version number and exit')
@ -714,30 +718,35 @@ def speedtest():
for i in range(0, 4): for i in range(0, 4):
urls.append('%s/random%sx%s.jpg' % urls.append('%s/random%sx%s.jpg' %
(os.path.dirname(best['url']), size, size)) (os.path.dirname(best['url']), size, size))
if not args.simple: if not args.uploadonly:
print_('Testing download speed', end='') if not args.simple:
dlspeed = downloadSpeed(urls, args.simple) print_('Testing download speed', end='')
if not args.simple: dlspeed = downloadSpeed(urls, args.simple)
print_() if not args.simple:
print_('Download: %0.2f M%s/s' % print_()
((dlspeed / 1000 / 1000) * args.units[1], args.units[0])) print_('Download: %0.2f M%s/s' %
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)] if not args.downloadonly:
sizes = [] sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
for size in sizesizes: sizes = []
for i in range(0, 25): for size in sizesizes:
sizes.append(size) for i in range(0, 25):
if not args.simple: sizes.append(size)
print_('Testing upload speed', end='') if not args.simple:
ulspeed = uploadSpeed(best['url'], sizes, args.simple) print_('Testing upload speed', end='')
if not args.simple: ulspeed = uploadSpeed(best['url'], sizes, args.simple)
print_() if not args.simple:
print_('Upload: %0.2f M%s/s' % print_()
((ulspeed / 1000 / 1000) * args.units[1], args.units[0])) print_('Upload: %0.2f M%s/s' %
((ulspeed / 1000 / 1000) * args.units[1], args.units[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.uploadonly or args.downloadonly):
print_('Cannot generate a speedtest.net share results image while '
'testing only upload or download speed')
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))