Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. # List of domains that should point to the current IP
  2. freedns_domains = set(["foo.example.com"])
  3.  
  4. # FreeDNS API endpoint, accessible from https://freedns.afraid.org/api/ (use the ASCII one)
  5. freedns_check_url = "https://freedns.afraid.org/api/?action=getdyndns&sha=REDACTED"
  6.  
  7. # It is assumed that this address responds with a page containing only the IP address
  8. ip_check_url = "https://ident.me/"
  9.  
  10.  
  11. def log(message):
  12. """
  13. Appends a string to the logfile (hardcoded as log.txt).
  14. :param message: The message to be appended. Linebreaks are your responsibility.
  15. """
  16. with open("log.txt", "a") as f:
  17. f.write(message)
  18.  
  19.  
  20. import datetime
  21. now = datetime.datetime.now()
  22. log("nn" + str(now) + ": Script executing,")
  23. import urllib.request
  24. current_ip = urllib.request.urlopen(ip_check_url).read().decode("utf-8")
  25. log(" IP: " + current_ip)
  26.  
  27. log("ntGetting FreeDNS records...")
  28. import urllib.request
  29. records_raw = urllib.request.urlopen(freedns_check_url).read().decode("utf-8").split("n")
  30. log(" Found " + str(len(records_raw)) + ".")
  31.  
  32. for raw_record in records_raw:
  33. parts = raw_record.split("|")
  34.  
  35. domain = parts[0]
  36. current_freedns_ip = parts[1]
  37. freedns_update_url = parts[2]
  38.  
  39. if domain not in freedns_domains:
  40. log("ntt" + domain + " is not on the watch list, skipping.")
  41. else:
  42. log("ntt" + domain + " (" + current_freedns_ip + ") is on the watch list...")
  43.  
  44. if current_ip == current_freedns_ip:
  45. log(" IPs already match, moving on.")
  46. else:
  47. log(" IPs don't match, updating...")
  48. urllib.request.urlopen(freedns_update_url)
  49. log(" done.")
  50.  
  51.  
  52. log("ntScript exited gracefully.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement