VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
热网互联2026年促销活动
hostkvm优惠促销活动
zji优惠促销活动

开源个godaddy ddns python脚本

主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

脚本,Python3…

  1. import json
  2. import re
  3. import os
  4. from sys import exit
  5. from urllib import request
  6. from urllib.error import HTTPError
  7. # Begin settings
  8. # Get the Production API key/secret from https://developer.godaddy.com/keys/.
  9. # Ensure it’s for “Production” as first time it’s created for “Test”.
  10. KEY = None  # <API production key&gt;
  11. SECRET = None  # <API secret&gt;
  12. # set call API header
  13. HEADERS = {
  14.     “Accept”: “application/json”,
  15.     ‘Content-type’: ‘application/json’,
  16.     ‘Authorization’: ‘sso-key {}:{}’.format(KEY, SECRET)
  17. }
  18. # Domain to update.
  19. DOMAIN = None  # <domain name&gt;
  20. # Advanced settings – change only if you know what you’re doing ?
  21. # Record type, as seen in the DNS setup page, default A.
  22. TYPE = ‘A’
  23. # Record name, as seen in the DNS setup page, default @.
  24. NAME = ‘@’
  25. # Time To Live in seconds, minimum default 600 (10mins).
  26. # If your public IP seldom changes, set it to 3600 (1hr) or more for DNS servers cache performance.
  27. TTL = 600
  28. # godaddy API URL
  29. GOD_ADDY_API_URL = “https://api.godaddy.com/v1/domains/{}/records/{}/{}”.format(DOMAIN, TYPE, NAME)
  30. # Writable path to last known Public IP record cached. Best to place in tmpfs.
  31. CACHED_IP_FILE = ‘/tmp/current_ip
  32. CACHED_IP = None
  33. if os.path.isfile(CACHED_IP_FILE):
  34.     CACHED_IP = open(CACHED_IP_FILE, mode=”r”, encoding=”utf-8″).read()
  35. # External URL to check for current Public IP, must contain only a single plain text IP.
  36. # Default http://api.ipify.org.
  37. CHECK_URL = ‘http://api.ipify.org’
  38. if not KEY or not SECRET:
  39.     print(“Error: Requires API ‘Key/Secret’ value.”)
  40.     exit(1)
  41. if not DOMAIN:
  42.     print(“Error: Requires ‘Domain’ value.”)
  43.     exit(1)
  44. # Get Host Public IP
  45. PUBLIC_IP = request.urlopen(CHECK_URL).read().decode(‘utf-8’)
  46. regex = r”^d{1,3}.d{1,3}.d{1,3}.d{1,3}$”
  47. if re.search(regex, PUBLIC_IP):
  48.     print(“Get Public IP: {}”.format(PUBLIC_IP))
  49. else:
  50.     print(“Fail! Public IP: {}”.format(PUBLIC_IP))
  51.     exit(1)
  52. # Check if the IP needs to be updated
  53. if CACHED_IP != PUBLIC_IP:
  54.     req = request.Request(url=GOD_ADDY_API_URL, headers=HEADERS)
  55.     try:
  56.         with request.urlopen(req) as response:
  57.             data = json.loads(response.read().decode(‘utf-8’))
  58.             NAME_BIND_IP = data[0][“data”] if data else None
  59.     except HTTPError as e:
  60.         if e.code in (422, 404):
  61.             NAME_BIND_IP = None
  62.     if NAME_BIND_IP == PUBLIC_IP:
  63.         print(“unchanged! Current ‘Public IP’ matches ‘GoDaddy’ records. No update required!”)
  64.     else:
  65.         print(“changed! Updating ‘{}.{}’, {} to {}”.format(NAME, DOMAIN, NAME_BIND_IP, PUBLIC_IP))
  66.         data = json.dumps([{“data”: PUBLIC_IP, “name”: NAME, “ttl”: TTL, “type”: TYPE}]).encode(‘utf-8’)
  67.         req = request.Request(url=GOD_ADDY_API_URL, data=data, headers=HEADERS, method=’PUT’)
  68.         with request.urlopen(req) as response:
  69.             print(“Success!” if not response.read().decode(‘utf-8’) else “Success!”)
  70.             open(‘/tmp/current_ip’, mode=”w”, encoding=”utf-8″).write(PUBLIC_IP)
  71. else:
  72.     print(“Current ‘Public IP’ matches ‘Cached IP’ recorded. No update required!”)

复制代码

README

  1. mkdir script
  2. cd script/
  3. wget https://raw.githubusercontent.com/anshengme/ddns/master/godaddy_for_python.py
  4. crontab -e
  5. */5 * * * * /usr/bin/python3 /root/script/godaddy_for_python.py &gt;&gt; /var/log/godaddy_for_python.py.log

复制代码

贴上GitHub: https://github.com/anshengme/ddns

各路大神的回复:

注册: 好东西,收藏了

ansheng: 一般不是到手cf么 、 不过也谢谢大佬

我是大水逼: 我的域名现在放在狗爹,所以就弄狗爹的了,如果是CF,到时候在撸个CF就好了

这几篇文章你可能也喜欢:

  • 暂无相关推荐文章

本文由主机参考刊发,转载请注明:开源个godaddy ddns python脚本 https://dev-web.zhujicankao.com/21140.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 开源个godaddy ddns python脚本
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!