Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97917

how to get python socket to use a specific interface

From Robin Becker <robin@reportlab.com>
Subject how to get python socket to use a specific interface
Date 2015-10-23 10:03 +0100
Newsgroups comp.lang.python
Message-ID <mailman.113.1445591037.878.python-list@python.org> (permalink)

Show all headers | View raw


I need to run lynx on a ubuntu headless server with a specific IP address in 
order to try and cancel an email blacklist.

Lynx doesn't provide a way to do that so I thought to use a local proxy. I tried 
pymiproxy and hacked the connection code so it looked like this


proxy.py
........
> from socket import socket, SOL_SOCKET
> .......
> import os
> BIND_ADDRESS = os.environ.get('PYMIPROXY_BIND_ADDRESS',None)
> BIND_DEVICE = os.environ.get('PYMIPROXY_BIND_DEVICE',None)
> .............
>         # Connect to destination
>         sock = self._proxy_sock = socket()
>         sock.settimeout(10)
>         if BIND_ADDRESS:
>             sock.bind((BIND_ADDRESS, 0))
>         if BIND_DEVICE:
>             sock.setsockopt(SOL_SOCKET, 25, BIND_DEVICE)
>         sock.connect((self.hostname, int(self.port)))

25 is derived from /usr/include/asm-generic/socket.h

> #define SO_BINDTODEVICE 25


This works if I export BIND_DEVICE='eth0' and run as root, but my desired 
interface is actually called 'eth0:0' and when I run with that exported I get a 
device error. Does anyone know what I should call the device?
-- 
Robin Becker

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

how to get python socket to use a specific interface Robin Becker <robin@reportlab.com> - 2015-10-23 10:03 +0100

csiph-web