Skip to content

Instantly share code, notes, and snippets.

@hossinasaadi
Created January 19, 2022 15:15
Show Gist options
  • Save hossinasaadi/32fe91bf4f1e380a041e06335a8ba6c8 to your computer and use it in GitHub Desktop.
Save hossinasaadi/32fe91bf4f1e380a041e06335a8ba6c8 to your computer and use it in GitHub Desktop.
Bind IP to requests library python
# 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