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


Groups > comp.lang.python > #97917 > unrolled thread

how to get python socket to use a specific interface

Started byRobin Becker <robin@reportlab.com>
First post2015-10-23 10:03 +0100
Last post2015-10-23 10:03 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#97917 — how to get python socket to use a specific interface

FromRobin Becker <robin@reportlab.com>
Date2015-10-23 10:03 +0100
Subjecthow to get python socket to use a specific interface
Message-ID<mailman.113.1445591037.878.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web