[Python] 纯文本查看 复制代码
import requests
import os
import time
mysession = requests.session()
headers = {
'Host': 'api.zhujiwu.com',
'Content-Length': '46',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://www.zhujiwu.com',
'Referer': 'http://www.zhujiwu.com/',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'close'}
def login(username, pwd):
url = "http://www.zhujiwu.com/www/login.php"
data = {
"cmd": "login",
"username": username,
"password": pwd
}
try:
r = mysession.post(url=url, data=data, headers=headers)
if r.json()['response'] == '200':
print('主机屋账户:【' + username + '】登陆成功!')
print("当前Cookies:", mysession.cookies)
else:
print(r.json())
except Exception as e:
print(e)
def get_history(domain):
url = "http://www.zhujiwu.com/www/domain.php"
data = {
"cmd": "jiexi_query",
"count": "10",
"page": "1",
"domainname": domain,
"title": ""}
r = mysession.post(url=url, data=data, headers=headers)
if r.json()['response'] == "200":
dns_history = r.json()['data']['content']
print(domain)
for i in dns_history:
print(i["id"], i["set_type"], i["title"], i["content"])
return dns_history
else:
return
def get_realIP():
real_IP = os.popen('curl ip.sb').read()
print("本机IP:", real_IP)
return real_IP
def change_dns(domai_id, realIP, domainname):
url = "http://www.zhujiwu.com/www/domain.php"
realIP = realIP.replace("\n", "")
data = {
'cmd': 'jiexi_modify',
'ac_id': domai_id,
'mx': '',
'content': realIP,
'ttl': '120'
}
r = mysession.post(url=url, data=data, headers=headers)
if r.json()['response'] == "200":
print("修改【", domainname, "】解析到【", realIP, "】成功")
else:
print("修改【", domainname, "】解析到【", realIP, "】失败")
if __name__ == '__main__':
username = ''
pwd = ''
domain = ""
login(username, pwd)
while 1:
dns_history = get_history(domain)
realIP = get_realIP().replace("\n", "")
for i in dns_history:
if realIP != i["content"]:
print("检测IP变更,修改解析:", end=" ")
change_dns(i["id"], realIP, i["title"])
time.sleep(60)