Created
January 29, 2024 12:34
-
-
Save lwzm/58d2c88d070bf7b58af78907d0f97347 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 | |
r''' | |
socat tcp-listen:1,fork exec:./ddns-via-socat.py | |
# client: | |
{echo xxxx-password && sleep 9} | nc x.x.x.x 1 | |
''' | |
import sys | |
from datetime import datetime | |
from os import getenv | |
from requests import Session | |
def update_dnspod(sub_domain, ip): | |
token = '49794,axxxc22xxxxxxxxxxx15' | |
session = 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() | |
def main(): | |
ip = getenv("SOCAT_PEERADDR") | |
password = input() | |
print(datetime.now(), ip, password, file=sys.stderr) | |
if password != '0o0': | |
print('err') | |
return | |
o = update_dnspod('hdlc', ip) | |
print(o, file=sys.stderr) | |
print(o, flush=True) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment