Created
January 1, 2020 13:22
-
-
Save eirenik0/e1094cdd855a74d7bbcaf4784bb2057d to your computer and use it in GitHub Desktop.
Get IP address
This file contains hidden or 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 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