I have two network adapters in Windows 7 environment, and both of them are connected to Internet:
- Ethernet Adapter (local address 10.9.187.251, external address 32.181.63.52)
- Wireless LAN Adapter (local address 192.168.1.178, external address 5.7.68.81)
Ethernet Adapter is used by default.
I want to make a connection with outgoing external address 5.7.68.81 through Wireless LAN in Python script.
I do following:
import pycurl, StringIO, re
c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://myproxylists.com/my-http-headers')
c.setopt(pycurl.INTERFACE, "192.168.1.178")
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.SSL_VERIFYPEER, False)
c.setopt(pycurl.SSL_VERIFYHOST, False)
c.perform()
rsp = b.getvalue()
mtch = re.search(r'REMOTE_ADDR == (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', rsp)
print mtch.group(1)
And I get printout:
32.181.63.52
So default adapter was used. It seems like c.setopt(pycurl.INTERFACE, "192.168.1.178")
doesn't work or I use it wrong way.
Also I tried all answers from this question with urllib2
and socket.bind(('192.168.1.178', 0)
- the same result.
How do I specify network interface for outgoing connection using Python 2.7 in Windows 7?