Specifying an IP address for outbound connections?

E

erikcw

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?

Thanks!
 
M

Martin v. Löwis

erikcw said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top