Q: HTTP through multiple NICs

Ng Pheng Siong ngps at madcap.dyndns.org
Fri Jul 13 13:42:02 EDT 2001


According to Gardiner, Geoff <ggardiner at accelrys.com>:
> I need to send HTTP traffic through multiple NICs (multihoming with
> different IP addresses AND different MAC addresses) on a single PC. The
> traffic doesn't need to be simultaneous (I think I'll try to walk before I
> run).

The archetypal TCP client socket example goes like this:

    from socket import *
1   s = socket(AF_INET, SOCK_STREAM)
2   s.connect((addr, port))
    s.send('blah blah blah')
    <etc.>

To do what you want, insert "s.bind((local_addr, local_port))" between
lines 1 and 2. Yes, bind() works for client sockets, too.

For this to work, your host's networking, routing, etc. must be configured
correctly, of course.

(A while ago, I used M2Crypto.SSL sockets with the bind() thingy above to
test so-called server load balancers' SSL session-id persistence when the
SSL session resumption requests come from different IP addresses, which
happens because certain ISPs were implementing transparent HTTP/HTTPS
proxying thru their cache farms, fronted by _their_ load balancers.)


A quick glance thru httplib shows no mechanism to pass your own socket
objects in - httplib's HTTP and HTTPConnection classes want to create their
own sockets. 

You can subclass either of those (use HTTPConnection, it's newer ;-) to pass
in your own sockets that bind to your choice of local address.


-- 
Ng Pheng Siong <ngps at post1.com> * http://www.post1.com/home/ngps

Quidquid latine dictum sit, altum viditur.



More information about the Python-list mailing list