Rev2054, Outgoing socket binding support

This commit is contained in:
shortcutme 2017-04-14 16:05:42 +02:00
parent c5629adf23
commit fae5d22e86
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
4 changed files with 25 additions and 4 deletions

View file

@ -179,3 +179,18 @@ def timerCaller(secs, func, *args, **kwargs):
def timer(secs, func, *args, **kwargs):
gevent.spawn_later(secs, timerCaller, secs, func, *args, **kwargs)
def create_connection(address, timeout=None, source_address=None):
if address in config.ip_local:
sock = socket.create_connection_original(address, timeout, source_address)
else:
sock = socket.create_connection_original(address, timeout, socket.bind_addr)
return sock
def socketBindMonkeyPatch(bind_ip, bind_port):
import socket
logging.info("Monkey patching socket to bind to: %s:%s" % (bind_ip, bind_port))
socket.bind_addr = (bind_ip, int(bind_port))
socket.create_connection_original = socket.create_connection
socket.create_connection = create_connection