Monday, December 21, 2009

Source interface with Python and urllib2 - Stack Overflow

A monkey patch to change your source interface with python Source interface with Python and urllib2
import socket
true_socket = socket.socket
def bound_socket(*a, **k):
    sock = true_socket(*a, **k)
    sock.bind((sourceIP, 0))
    return sock
socket.socket = bound_socket

No comments: