How set the source IP adress
grante at visi.com
Fri Oct 27 20:25:41 CEST 2006
On 2006-10-27, Grant Edwards <grante at visi.com> wrote:
> On 2006-10-27, Irmen de Jong <irmen.NOSPAM at xs4all.nl> wrote:
>>> how to set source ip-address when do __socket.connect((host, port))
>>> on a machine that have a several ip-adresses?
>>> __socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> __socket.connect((host, port))
>> sock.connect ( ('188.8.131.52', 9999) )
>> i.e. just put the ip address as string parameter into the
>> connect address tuple (where you wrote: host)
> Um, no. That controls the _destination_ IP address, not the
> source. If you want to control the source IP addresss you can
> bind it to a local interface's IP address before doing the
> connect() call.
> sock.bind(('10.0.0.99',-1)) # -1: don't care about source port number
Doh! That should have been 0 not -1.
Grant Edwards grante Yow! Do I hear th'
at SPINNING of various
visi.com WHIRRING, ROUND, and WARM
More information about the Python-list