Skip to content

Instantly share code, notes, and snippets.

@marios8543
Created April 24, 2019 18:16
Show Gist options
  • Save marios8543/f68de97419138a7de5032e4be9fee894 to your computer and use it in GitHub Desktop.
Save marios8543/f68de97419138a7de5032e4be9fee894 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
INTERVAL = 300
DOMAINS = [
{
"domain":"",
"password":"",
"host":"@"
}
]
import requests
from time import sleep
def _get_ip():
res = requests.get("https://api.ipify.org/")
if res.status_code==200:
return res.text
LAST_IP = None
def _update_ip(domain,password,host):
res = requests.get("https://dynamicdns.park-your-domain.com/update",data={
"host":host,
"domain":domain,
"password":password,
"ip":LAST_IP
})
if res.status_code==200:
return True
else:
return res.text
while True:
try:
ip = _get_ip()
if not ip:
print("Something went wrong with the IP API")
elif ip and ip!=LAST_IP:
print("Updating IP to {}".format(ip))
LAST_IP = ip
for i in DOMAINS:
up = _update_ip(i["domain"],i["password"],i["host"])
if type(up)==bool:
print("Updated IP for {}".format(i["domain"]))
else:
print("""
Something went wrong updating {}
Error message: {}
""".format(i["domain"],up))
finally:
print("Sleeping for {} seconds".format(INTERVAL))
sleep(INTERVAL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment