From 62cbd36364fa0344f7a71a414a85cbc38e2e77cc Mon Sep 17 00:00:00 2001 From: potchin Date: Mon, 6 Feb 2017 14:16:39 +0000 Subject: [PATCH] Support running against targets without netstat Not all remote hosts have netstat installed (eg minimal installations, hypervisors). sshuttle should at least work in these instances, rather than failing with an OSError --- sshuttle/server.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sshuttle/server.py b/sshuttle/server.py index 4ae2749..d4d70af 100644 --- a/sshuttle/server.py +++ b/sshuttle/server.py @@ -60,10 +60,19 @@ def _shl(n, bits): def _list_routes(): # FIXME: IPv4 only argv = ['netstat', '-rn'] - p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE) + env = { + 'PATH': os.environ['PATH'], + 'LC_ALL': "C", + } routes = [] + try: + p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=env) + except OSError: + log("WARNING: Unable to run %r on remote host.\n"%argv) + log('WARNING: That prevents --auto-nets from working.\n') + return routes for line in p.stdout: - cols = re.split(b'\s+', line) + cols = re.split(r'\s+', line.decode("ASCII")) ipw = _ipmatch(cols[0]) if not ipw: continue # some lines won't be parseable; never mind