通过青龙面板自动运行
通过腾讯视频api获取本机IP地址,更新到域名解析,记录到数据库,也可以不记录到数据库
[Python] 纯文本查看 复制代码import requests
import time
import datetime
import pymysql
def get_external_ip():
try:
response = requests.get("https://vv.video.qq.com/checktime?otype=ojson")
ip = response.json()["ip"]
return ip
except:
return None
#dtip=""
with open('zzip.txt', 'r', encoding='utf-8') as file:
dtip = file.read()
for i in range(1,300):
ip=get_external_ip()
if dtip!=ip:
url="https://api.masktt.com/dnspod/?token=***&ip="+ip
req=requests.get(url)
print("ip已于",datetime.datetime.now(),"更新为:",ip)
dtip=ip
# 连接数据库
conn = pymysql.connect(host='数据库IP地址', user='数据库用户名', password='数据库密码', db='数据库表名')
cursor = conn.cursor()
# 执行插入操作
sql = "INSERT INTO zzip (dttime, dtday,ip) VALUES (now(),%s, %s)"
data = ('动态IP', dtip)
cursor.execute(sql, data)
# 提交事务
conn.commit()
# 关闭数据库连接
cursor.close()
with open('zzip.txt', 'w') as file:
## 将文本写入文件
file.write(ip)
else:
print(ip,"ip没有变化",datetime.datetime.now())
time.sleep(600)
不记录IP地址变化,直接只更新域名解析
[Python] 纯文本查看 复制代码import requests
import time
import datetime
def get_external_ip():
try:
response = requests.get("https://vv.video.qq.com/checktime?otype=ojson")
ip = response.json()["ip"]
return ip
except:
return None
#dtip=""
with open('zzip.txt', 'r', encoding='utf-8') as file:
dtip = file.read()
for i in range(1,300):
ip=get_external_ip()
if dtip!=ip:
## 将域名解析更新的链接写入下面
url="https://api.masktt.com/dnspod/?token=***&ip="+ip
req=requests.get(url)
print("ip已于",datetime.datetime.now(),"更新为:",ip)
dtip=ip
with open('zzip.txt', 'w') as file:
## 将文本写入文件
file.write(ip)
else:
print(ip,"ip没有变化",datetime.datetime.now())
time.sleep(600)