Last active
January 14, 2020 03:46
-
-
Save lwzm/48b8b5ef4f7b73b5c1d485b5ba9f492f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import requests | |
def update_dnspod(sub_domain, ip): | |
token = '49794,a259c8cdfc221e32078e867fdfea0415' | |
session = requests.Session() | |
session.headers["User-Agent"] = "Py/3.x ([email protected])" | |
data = { | |
"format": "json", | |
"login_token": token, | |
} | |
resp = session.post("https://dnsapi.cn/Domain.List", data) | |
domains = resp.json() | |
for domain in domains["domains"]: | |
if domain["name"] == 'tyio.net': | |
data["domain_id"] = domain["id"] | |
break | |
else: # for ... else ... | |
raise ValueError(domains) | |
resp = session.post("https://dnsapi.cn/Record.List", data) | |
records = resp.json() | |
for record in records["records"]: | |
if record["name"] == sub_domain: | |
data["record_id"] = record["id"] | |
if record['value'] == ip: | |
return 'not change', ip | |
break | |
else: # for ... else ... | |
raise ValueError(records) | |
data.update({ | |
"sub_domain": sub_domain, | |
"record_type": "A", | |
"record_line": "默认", | |
"value": ip, | |
"ttl": 600, | |
}) | |
resp = session.post("https://dnsapi.cn/Record.Modify", data) | |
return resp.json() | |
if __name__ == '__main__': | |
o = update_dnspod('my-pro', requests.get('http://ip.tyio.net').text.strip()) | |
print(o) |
This file contains hidden or 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
while true; do | |
date | |
./ddns.py | |
ssh -C -N -R 127.3.3.2:65222:localhost:22 tyio.net | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment