-
-
Save kaseiwang/4c7bc52b8d313e1a94f4 to your computer and use it in GitHub Desktop.
A Dnspod DDNS Update shell, Python Version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import socket | |
import time | |
socket.setdefaulttimeout(10) | |
TIMEOUT=60 | |
params = { | |
"login_email"="[email protected]", | |
"login_password"="yourpassword", | |
"format"="json", | |
"domain_id"=yourid, | |
"record_id"=yourid, | |
"sub_domain"="your_sub_domain", | |
"record_line"="默认", | |
"format":"JSON" | |
} | |
current_ip = None | |
def ddns(ip): | |
params.update({"value":ip}) | |
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json","User-Agent":"PanDDNSPython/ver.Alpha([email protected])"} | |
try: | |
post = requests.post("https://dnsapi.cn/Record.Ddns", params = params,headers = headers,timeout = 10).json() | |
except: | |
print("NetERROR"); | |
return False; | |
print("[{}]{} @ {}".format(post["status"]["created_at"],post["status"]["message"],post["record"]["value"])) | |
return True | |
def getip(): | |
return requests.get("http://members.3322.org/dyndns/getip",timeout=10).text[:-1] | |
if __name__ == '__main__': | |
while True: | |
try: | |
ip = getip() | |
if current_ip != ip: | |
print("[{}] New IP get '{}' , try to refresh...".format(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),ip)) | |
if ddns(ip): | |
current_ip = ip | |
except Exception as e: | |
print("[{}] Oops,Error:{}".format(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),e)) | |
time.sleep(TIMEOUT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment