Added interface functionality

Now it's possible to do the speed test over a specific interface for example eth0 or tun1 etc
This commit is contained in:
adidgit 2017-12-11 21:31:36 +02:00 committed by GitHub
parent 20e5d12a5c
commit 6a47d7e99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -363,6 +363,16 @@ def bound_socket(*args, **kwargs):
sock = SOCKET_SOCKET(*args, **kwargs)
sock.bind((SOURCE, 0))
return sock
def socket_interface(*args, **kwargs):
"""Bind socket to a specified interface"""
sock = SOCKET_SOCKET(*args, **kwargs)
sock.setsockopt(socket.SOL_SOCKET, 25, INTERFACE)
sock.bind(("", 0))
return sock
def distance(origin, destination):
@ -1277,6 +1287,7 @@ def parse_args():
type=PARSER_TYPE_INT)
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('--interface', help='Interface to be used')
parser.add_argument('--timeout', default=10, type=PARSER_TYPE_INT,
help='HTTP timeout in seconds. Default 10')
parser.add_argument('--secure', action='store_true',
@ -1338,7 +1349,7 @@ def printer(string, quiet=False, debug=False, **kwargs):
def shell():
"""Run the full speedtest.net test"""
global SHUTDOWN_EVENT, SOURCE, SCHEME, DEBUG
global SHUTDOWN_EVENT, SOURCE, SCHEME, DEBUG, INTERFACE
SHUTDOWN_EVENT = threading.Event()
signal.signal(signal.SIGINT, ctrl_c)
@ -1367,6 +1378,10 @@ def shell():
if args.source:
SOURCE = args.source
socket.socket = bound_socket
if args.interface:
INTERFACE = args.interface
socket.socket = socket_interface
if args.secure:
SCHEME = 'https'