Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created August 10, 2013 13:32
Show Gist options
  • Save pandada8/6200455 to your computer and use it in GitHub Desktop.
Save pandada8/6200455 to your computer and use it in GitHub Desktop.
A Dnspod DDNS Update shell, Python Version
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