Skip to content

Instantly share code, notes, and snippets.

@kevinblake
Last active December 31, 2015 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinblake/8005620 to your computer and use it in GitHub Desktop.
Save kevinblake/8005620 to your computer and use it in GitHub Desktop.
Sends a pushover message, whenever your public IP address changes.
import requests,json,time,httplib, urllib, socket, yaml
f = open('ip.yaml')
settings = yaml.safe_load(f)
f.close()
while True:
f = open('ipaddress', 'r')
current = f.readline()
r=requests.get(r'http://jsonip.com')
rjs = r.json()
msg=socket.gethostname() + ": " + rjs['ip']
if r.status_code == 200 and current != msg and rjs['ip'] != '' and rjs['ip'] is not None:
f = open('ipaddress', 'w')
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": settings["config"]["pushover"]["apiKey"],
"user": settings["config"]["pushover"]["userKey"],
"message": msg,
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
f.write(msg)
time.sleep(300)
config:
pushover:
apiKey: <Application-Token, get from www.pushover.net>
userKey: <User-Token, get from user token>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment