ddns_script/ddns_801.py
2022-04-23 21:18:04 +08:00

32 lines
926 B
Python

from porkbun_ddns import PorkbunAPI
from getRouterIP import GetRouterWanIP
import re
from dns.resolver import resolve
API_Key = "pk1_我删了"
Secret_Key = "sk1_我删了"
def check_ip(ip_addr):
compile_ip = re.compile(
'^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$')
if compile_ip.match(ip_addr):
return True
else:
return False
GetRouterWanIP.check_info_exist()
getRouterWanIP = GetRouterWanIP()
getRouterWanIP.get_stok()
ip = getRouterWanIP.get_wan_ip()
print(ip)
if check_ip(ip):
if str(resolve("wis01.marques22.com", 'A')[0]) != ip:
porkbun_api = PorkbunAPI("marques22.com", API_Key, Secret_Key)
porkbun_api.edit_A_with_name("wis01", ip)
print("edit end")
else:
print("ip not change")
else:
print("ipv4 formation is wrong!")