Path: csiph.com!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '#define': 0.07; 'root,': 0.07; 'socket': 0.07; '0))': 0.09; 'derived': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:python': 0.14; '.........': 0.16; 'exported': 0.16; 'hacked': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sock': 0.16; 'looked': 0.16; 'tried': 0.24; 'import': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'cancel': 0.27; 'device': 0.28; 'interface': 0.29; 'socket,': 0.29; 'connection': 0.30; 'code': 0.30; 'error.': 0.31; 'anyone': 0.32; 'skip:. 10': 0.32; 'run': 0.33; 'ubuntu': 0.33; 'server': 0.34; 'subject:use': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'received:org': 0.37; 'desired': 0.37; 'thought': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'address': 0.61; 'provide': 0.61; 'export': 0.63; 'received:109': 0.75; 'subject:get': 0.81; 'becker': 0.84; 'skip:/ 30': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robin Becker Subject: how to get python socket to use a specific interface Date: Fri, 23 Oct 2015 10:03:41 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 109.174.168.73 X-Mozilla-News-Host: news://news.gmane.org:119 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1445591037 news.xs4all.nl 23762 [2001:888:2000:d::a6]:47917 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97917 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