fall back to default IP if there's no internet connection

This commit is contained in:
Michel Oosterhof 2015-07-20 22:47:17 +01:00
parent 93990528c3
commit 00477f777b
1 changed files with 7 additions and 4 deletions

View File

@ -53,10 +53,13 @@ class HoneyPotBaseProtocol(insults.TerminalProtocol):
self.kippoIP = self.cfg.get('honeypot', 'internet_facing_ip')
else:
# Hack to get ip
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
self.kippoIP = s.getsockname()[0]
s.close()
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
self.kippoIP = s.getsockname()[0]
s.close()
except:
self.kippoIP = '192.168.0.1'
# this is only called on explicit logout, not on disconnect
# this indicates the closing of the channel/session, not the closing of the connection