自己在外访问家里虚机上很多服务,拨号的IP总是在变,干脆自己弄一个更新公网IP的python脚本。 ```python import sys import requests import re import time #使用了godaddypy的api from godaddypy import Client, Account domain = 'xciel.us' #更新www记录和域名根记录 a_record = 'www' b_record = '@' #查询公网IP的地址 checkPublicIP = 'https://api.ipify.org/' def get_ip(a): response = requests.get(a) my_ip = re.search(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",response.content.decode(errors='ignore')).group(0) return my_ip try: publicIP = get_ip(checkPublicIP) #查询公网IP无法访问时异常处理 except: print("无法访问查询网站:"+checkPublicIP) else: #添加时间标记 thisTime = time.strftime("%Y年%m月%d日 %H:%M:%S", time.localtime()) userAccount = Account(api_key='你的API-KEY', api_secret='你的API-SECRET') userClient = Client(userAccount) recordsA = userClient.get_records(domain, name=a_record, record_type='A') recordsB = userClient.get_records(domain, name=b_record, record_type='A') if publicIP != recordsA[0]["data"]: if userClient.update_record_ip(publicIP, domain, a_record, 'A'): print('('+a_record+')记录更新完成!——'+thisTime) else: print('('+a_record+')更新失败!——'+thisTime) else: print('('+a_record+')记录无需更新。——'+thisTime) if publicIP != recordsB[0]["data"]: if userClient.update_record_ip(publicIP, domain, b_record, 'A'): print('('+b_record+')记录更新完成!——'+thisTime) else: print('('+b_record+')更新失败!——'+thisTime) else: print('('+b_record+')记录无需更新。——'+thisTime) ``` Last modification:March 25, 2020 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 If you think my article is useful to you, please feel free to appreciate