mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-04-20 17:28:30 +02:00
Small refactoring of netstat/iproute parsing
This commit is contained in:
parent
809fad537f
commit
d7d24f956b
@ -66,23 +66,19 @@ def _shl(n, bits):
|
|||||||
|
|
||||||
|
|
||||||
def _route_netstat(line):
|
def _route_netstat(line):
|
||||||
cols = re.split(r'\s+', line.decode("ASCII"))
|
cols = line.split(None)
|
||||||
ipw = _ipmatch(cols[0])
|
ipw = _ipmatch(cols[0])
|
||||||
if not ipw:
|
|
||||||
return None, None # some lines won't be parseable; never mind
|
|
||||||
maskw = _ipmatch(cols[2]) # linux only
|
maskw = _ipmatch(cols[2]) # linux only
|
||||||
mask = _maskbits(maskw) # returns 32 if maskw is null
|
mask = _maskbits(maskw) # returns 32 if maskw is null
|
||||||
return ipw, mask
|
return ipw, mask
|
||||||
|
|
||||||
|
|
||||||
def _route_iproute(line):
|
def _route_iproute(line):
|
||||||
ipm = line.decode("ASCII").split(None, 1)[0]
|
ipm = line.split(None, 1)[0]
|
||||||
if ipm == 'default':
|
if '/' not in ipm:
|
||||||
return None, None
|
return None, None
|
||||||
ip, mask = ipm.split('/')
|
ip, mask = ipm.split('/')
|
||||||
ipw = _ipmatch(ip)
|
ipw = _ipmatch(ip)
|
||||||
if not ipw:
|
|
||||||
return None, None # some lines won't be parseable; never mind
|
|
||||||
return ipw, int(mask)
|
return ipw, int(mask)
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +91,9 @@ def _list_routes(argv, extract_route):
|
|||||||
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=env)
|
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=env)
|
||||||
routes = []
|
routes = []
|
||||||
for line in p.stdout:
|
for line in p.stdout:
|
||||||
ipw, mask = extract_route(line)
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
ipw, mask = extract_route(line.decode("ASCII"))
|
||||||
if not ipw:
|
if not ipw:
|
||||||
continue
|
continue
|
||||||
width = min(ipw[1], mask)
|
width = min(ipw[1], mask)
|
||||||
|
Loading…
Reference in New Issue
Block a user