Last active
December 2, 2018 00:51
-
-
Save RyanBreaker/882a6aea3b8646c7ef7581dce1431617 to your computer and use it in GitHub Desktop.
A Python script that looks up and returns your public IP address. Requires the "requests" Python library to work.
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
#!/usr/local/bin/python3 | |
# Requires the requests library to work: | |
# $ pip install requests | |
import json, requests, sys | |
url = 'https://wtfismyip.com/json' | |
r = None | |
try: | |
r = requests.get(url) | |
except requests.ConnectionError: | |
# Fail elegantly if the server can't be reached | |
print('Connection failed, check your internet connection.') | |
sys.exit(1) | |
ip = json.loads(r.content) | |
print(ip['YourFuckingIPAddress']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment