Skip to content

Instantly share code, notes, and snippets.

@eirenik0
Created January 1, 2020 13:22
Show Gist options
  • Save eirenik0/e1094cdd855a74d7bbcaf4784bb2057d to your computer and use it in GitHub Desktop.
Save eirenik0/e1094cdd855a74d7bbcaf4784bb2057d to your computer and use it in GitHub Desktop.
Get IP address
import requests
def get_public_ip():
try:
r = requests.get('http://ip.o11.net', timeout=(2.0, 2.0))
if r.status_code == 200:
return r.text.rstrip()
except requests.RequestException:
warnings.warn(f'Cannot fetch public ip')
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment