Created
April 18, 2016 13:57
-
-
Save agramajo/6145047aa49af419c8d2600797cfe752 to your computer and use it in GitHub Desktop.
set source ip address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import requests | |
real_create_conn = socket.create_connection | |
#diferentes ips que salen por diferentes enlaces | |
ip1 = '192.168.1.2' | |
ip2 = '192.168.1.3' | |
#forzamos la ip1 | |
def set_src_addr1(*args): | |
address, timeout = args[0], args[1] | |
source_address = (ip1, 0) | |
return real_create_conn(address, timeout, source_address) | |
#forzamos la ip2 | |
def set_src_addr2(*args): | |
address, timeout = args[0], args[1] | |
source_address = (ip2, 0) | |
return real_create_conn(address, timeout, source_address) | |
socket.create_connection = set_src_addr1 | |
print ip1, requests.get('http://baicom.com/ip').content | |
socket.create_connection = set_src_addr2 | |
print ip2, requests.get('http://baicom.com/ip').content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's not working!