Controlling source IP address within urllib2

Dan tojuso at hotmail.com
Thu Jun 9 20:37:37 EDT 2005


Just FYI ... I finally got this to work.  Unfortunately, I was unable
to use the urllib2 library.  The embedded Linux team here informed me
that the urllib2 library will not be available on the machine I wanted
to deploy on, so I had to go back to using the urllib and httplib
libraries.  After trying several things, I finally gave up and hacked
the library code directly.  It turned out to be quite easy.  I just had
to wedge in a "self.sock.bind()" call in front of the
"self.sock.connect()" call within the HTTPConnection class inside the
httplib library.  (I used the bind() function to nail down the source
IP address of the client.)  Of course, I had to weave in some code that
allowed me to pass the client IP address through the URLopener class in
the urllib library.  Everything seems to work so far.

John, thanks again for your help.  You pointed me in the right
direction.

-Dan




More information about the Python-list mailing list