mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-08-14 10:15:01 +02:00
fix: route PRINT -4 to_ascii [windows]
Co-authored-by: clement.igonet <clement.igonet@exotrail.com>
This commit is contained in:
@ -80,17 +80,18 @@ def _route_iproute(line):
|
|||||||
|
|
||||||
|
|
||||||
def _route_windows(line):
|
def _route_windows(line):
|
||||||
if " On-link " not in line:
|
parts = re.split(r'\s+', line.strip())
|
||||||
|
if len(parts) < 4:
|
||||||
return None, None
|
return None, None
|
||||||
dest, net_mask = re.split(r'\s+', line.strip())[:2]
|
prefix = parts[3]
|
||||||
if net_mask == "255.255.255.255":
|
dest, mask = prefix.split('/')
|
||||||
|
if mask == "32":
|
||||||
return None, None
|
return None, None
|
||||||
for p in ('127.', '0.', '224.', '169.254.'):
|
for p in ('127.', '0.', '224.', '169.254.'):
|
||||||
if dest.startswith(p):
|
if dest.startswith(p):
|
||||||
return None, None
|
return None, None
|
||||||
ipw = _ipmatch(dest)
|
ipw = _ipmatch(dest)
|
||||||
mask = _maskbits(_ipmatch(net_mask))
|
return ipw, int(mask)
|
||||||
return ipw, mask
|
|
||||||
|
|
||||||
|
|
||||||
def _list_routes(argv, extract_route):
|
def _list_routes(argv, extract_route):
|
||||||
@ -100,7 +101,7 @@ def _list_routes(argv, extract_route):
|
|||||||
for line in p.stdout:
|
for line in p.stdout:
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
ipw, mask = extract_route(line.decode("ASCII"))
|
ipw, mask = extract_route(line.decode("ASCII", errors='ignore'))
|
||||||
if not ipw:
|
if not ipw:
|
||||||
continue
|
continue
|
||||||
width = min(ipw[1], mask)
|
width = min(ipw[1], mask)
|
||||||
@ -116,7 +117,7 @@ def _list_routes(argv, extract_route):
|
|||||||
|
|
||||||
def list_routes():
|
def list_routes():
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
routes = _list_routes(['route', 'PRINT', '-4'], _route_windows)
|
routes = _list_routes(['netsh', 'interface', 'ipv4', 'show', 'route'], _route_windows)
|
||||||
else:
|
else:
|
||||||
if which('ip'):
|
if which('ip'):
|
||||||
routes = _list_routes(['ip', 'route'], _route_iproute)
|
routes = _list_routes(['ip', 'route'], _route_iproute)
|
||||||
|
Reference in New Issue
Block a user