Specifying an IP address for outbound connections?

"Martin v. Löwis" martin at v.loewis.de
Wed Oct 29 03:29:03 EDT 2008


erikcw wrote:
> Python seems to default to the main system IP for outbound connections
> (such as urllib), but I want to bind to one of my other IPs for
> outbound connections.
> 
> Any ideas?

Just use the .bind method of a socket to bind it to a specific address.
If you then want to continue to use urllib, you'll have to override a
lot of classes, or monkey-patch, or use, e.g., PyContext to selectively
replace httplib.HTTPConnection.connect.

Regards,
Martin



More information about the Python-list mailing list