Created
January 19, 2022 15:15
-
-
Save hossinasaadi/32fe91bf4f1e380a041e06335a8ba6c8 to your computer and use it in GitHub Desktop.
Bind IP to requests library python
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
# bind source_address to requests | |
import urllib3 | |
real_create_conn = urllib3.util.connection.create_connection | |
def set_src_addr(address, timeout, *args, **kw): | |
source_address = ('YOUR_BIND_IP', 0) | |
return real_create_conn(address, timeout=timeout, source_address=source_address) | |
urllib3.util.connection.create_connection = set_src_addr | |
import requests | |
r = requests.get('http://ipecho.net/plain') | |
print( r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment