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