Advertisement
DeaD_EyE

duckdns.org

May 22nd, 2020
1,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. """
  2. Visit https://www.duckdns.org for more information.
  3.  
  4. It's a free dyndns service with easy registration.
  5. """
  6.  
  7.  
  8. from urllib.request import urlopen
  9.  
  10.  
  11. def update(token, *domains, ip=""):
  12.     """
  13.    The token and at least one domain is required for update.
  14.    The IP is optional. If the IP is not given, duckdns.org
  15.    uses the IP from the request source IP, which is your host.
  16.    """
  17.     url = "https://www.duckdns.org/update"
  18.     query = {
  19.         "domains": ",".join(domains),
  20.         "token": token,
  21.         "ip": ip,
  22.     }
  23.     url += "?" + "&".join(f"{key}={val}" for key, val in query.items())
  24.     try:
  25.         req = urlopen(url, timeout=10)
  26.     except Exception as e:
  27.         print(repr(e))
  28.         return False
  29.     if req.status == 200 and req.read() == b"OK":
  30.         return True
  31.     else:
  32.         return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement