1
setiepr 2016-04-05 18:29:20 +08:00
use module socket
http://stackoverflow.com/questions/12585317/requests-bind-to-an-ip |
2
setiepr 2016-04-05 18:29:56 +08:00
import socket
real_create_conn = socket.create_connection def set_src_addr(*args): address, timeout = args[0], args[1] source_address = ('IP_ADDR_TO_BIND_TO', 0) return real_create_conn(address, timeout, source_address) socket.create_connection = set_src_addr import requests r = requests.get('http://www.google.com') |