how to get python socket to use a specific interface

Robin Becker robin at reportlab.com
Mon Oct 26 08:33:43 EDT 2015


.............
>> device? --
>> Robin Becker
>
> Using eth0:0 is normally a method to setup eth0 to respond to a 2nd
> IPV4/IPV6 address.  Have you done the ifconfig steps to enable that?  If
> its been done, you will see it's 2nd address in an ifconfig query.  Man
> pages are wunnerful things.
yes I have done that and the address is responding, problem is it has been email 
blacklisted

> $ ifconfig
> eth0      Link encap:Ethernet  HWaddr 00:.......4 GB)
>           Interrupt:16
>
> eth0:0    Link encap:Ethernet  HWa.......
>
> lo        Link encap:Local Loopback
......


The problem is as stated in the original email; when I try to execute the 
commands to bind to that device I get an error eg


># ~rptlab/tmp/proxy/bin/python
> Python 2.7.5 (default, Aug 20 2013, 15:27:38)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from socket import socket, SOL_SOCKET
>>>> BIND_DEVICE='eth0:0'
>>>> sock = socket()
>>>> sock.settimeout(10)
>>>> sock.setsockopt(SOL_SOCKET, 25, BIND_DEVICE)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/rptlab/LOCAL/lib/python2.7/socket.py", line 224, in meth
>     return getattr(self._sock,name)(*args)
> socket.error: [Errno 19] No such device
>>>>


so I guess I'm not using the right name for the device. I tried a leter python 
3.5 in case my python 2.7 is too old, but that also fails.

-- 
Robin Becker




More information about the Python-list mailing list