Commit 4b5e9293 authored by Rick Yazwinski's avatar Rick Yazwinski

handle failed reverse connections gracefully

if netcat isn't listening on the reverse connect port, or we cannot
connect for some reason, then print a friendly error message and exit
the thread
parent 3a981689
...@@ -70,13 +70,18 @@ class ReverseConnection(threading.Thread, PyrasiteIPC): ...@@ -70,13 +70,18 @@ class ReverseConnection(threading.Thread, PyrasiteIPC):
continue continue
break break
if not self.sock:
raise Exception('pyrasite cannot establish reverse connection to %s:%d' % (self.host, self.port))
self.on_connect() self.on_connect()
while running: while running:
cmd = self.recv() cmd = self.recv()
if cmd is None or cmd == "quit\n" or len(cmd) == 0: if cmd is None or cmd == "quit\n" or len(cmd) == 0:
running = False running = False
else: else:
running = self.on_command(cmd) running = self.on_command(cmd)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
running = False running = False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment