Skip to content

Instantly share code, notes, and snippets.

@RyanBreaker
Last active December 2, 2018 00:51
Show Gist options
  • Save RyanBreaker/882a6aea3b8646c7ef7581dce1431617 to your computer and use it in GitHub Desktop.
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.
#!/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