From 0807b24feaf7e56b44cdbab25de68b08c7f44bee Mon Sep 17 00:00:00 2001 From: Dan McInerney Date: Sun, 9 Nov 2014 15:28:23 -0500 Subject: [PATCH] improved router IP finding function --- LANs.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/LANs.py b/LANs.py index 016d6a5..334dd10 100755 --- a/LANs.py +++ b/LANs.py @@ -166,17 +166,16 @@ def LANsMain(args): ipr = Popen(['/sbin/ip', 'route'], stdout=PIPE, stderr=DN) ipr = ipr.communicate()[0] iprs = ipr.split('\n') - ipr = ipr.split() - if args.routerip: - routerIP = args.routerip - else: - try: - routerIP = ipr[2] - except: - exit("You must be connected to the internet to use this.") + routerIP = None for r in iprs: if '/' in r: IPprefix = r.split()[0] + if r.startswith('default') and not args.routerip: + routerIP = r.split()[2] + if args.routerip: + routerIP = args.routerip + if not routerIP: + exit("You must be connected to the internet to use this.") if args.interface: interface = args.interface else: