From dbcf4c2f421605963e0c1780967c6f5261ab0505 Mon Sep 17 00:00:00 2001 From: Jonathan Cave Date: Mon, 29 Jun 2020 18:01:32 +0100 Subject: gateway_ping_test: fix crash when using networkctl When the information is available networkctl will include the manufacturer in the gateway status field in brackets. This handles that situation and problems splitting the line better. --- bin/gateway_ping_test | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/gateway_ping_test b/bin/gateway_ping_test index 7bac0f8..47dcfda 100755 --- a/bin/gateway_ping_test +++ b/bin/gateway_ping_test @@ -138,11 +138,12 @@ def get_host_to_ping(interface=None, verbose=False, default=None): try: output = subprocess.check_output(cmd, shell=True) for line in output.decode(sys.stdout.encoding).splitlines(): - key, val = line.strip().split(':', maxsplit=1) - if key == "Gateway": - subprocess.check_output(["ping", "-q", "-c", "1", val], - stderr=subprocess.STDOUT) - break + vals = line.strip().split(' ') + if len(vals) >= 2: + if vals[0] == 'Gateway:': + subprocess.check_output(["ping", "-q", "-c", "1", vals[1]], + stderr=subprocess.STDOUT) + break except subprocess.CalledProcessError: pass ARP_POPULATE_TRIES = 10 -- cgit v1.2.3