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

31 lines
882 B
Python

from porkbun_ddns import PorkbunAPI
from getRouterIP import GetRouterWanIP
import re
from dns.resolver import resolve
API_Key = "我删了"
Secret_Key = "我删了"
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()
if check_ip(ip):
if str(resolve("wis02.marques22.com", 'A')[0]) != ip:
porkbun_api = PorkbunAPI("marques22.com", API_Key, Secret_Key)
porkbun_api.edit_A_with_name("wis02", ip)
else:
print("ip not change")
else:
print("ipv4 formation is wrong!")