Last active
December 31, 2015 15:18
-
-
Save kevinblake/8005620 to your computer and use it in GitHub Desktop.
Sends a pushover message, whenever your public IP address changes.
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,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) | |
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
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