Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # List of domains that should point to the current IP
- freedns_domains = set(["foo.example.com"])
- # FreeDNS API endpoint, accessible from https://freedns.afraid.org/api/ (use the ASCII one)
- freedns_check_url = "https://freedns.afraid.org/api/?action=getdyndns&sha=REDACTED"
- # It is assumed that this address responds with a page containing only the IP address
- ip_check_url = "https://ident.me/"
- def log(message):
- """
- Appends a string to the logfile (hardcoded as log.txt).
- :param message: The message to be appended. Linebreaks are your responsibility.
- """
- with open("log.txt", "a") as f:
- f.write(message)
- import datetime
- now = datetime.datetime.now()
- log("nn" + str(now) + ": Script executing,")
- import urllib.request
- current_ip = urllib.request.urlopen(ip_check_url).read().decode("utf-8")
- log(" IP: " + current_ip)
- log("ntGetting FreeDNS records...")
- import urllib.request
- records_raw = urllib.request.urlopen(freedns_check_url).read().decode("utf-8").split("n")
- log(" Found " + str(len(records_raw)) + ".")
- for raw_record in records_raw:
- parts = raw_record.split("|")
- domain = parts[0]
- current_freedns_ip = parts[1]
- freedns_update_url = parts[2]
- if domain not in freedns_domains:
- log("ntt" + domain + " is not on the watch list, skipping.")
- else:
- log("ntt" + domain + " (" + current_freedns_ip + ") is on the watch list...")
- if current_ip == current_freedns_ip:
- log(" IPs already match, moving on.")
- else:
- log(" IPs don't match, updating...")
- urllib.request.urlopen(freedns_update_url)
- log(" done.")
- log("ntScript exited gracefully.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement