Skip to content

Instantly share code, notes, and snippets.

@misaka10843
Created January 24, 2022 15:42
Show Gist options
  • Save misaka10843/e92fb8a09f2fbda6bcc4f0c915a7a0b4 to your computer and use it in GitHub Desktop.
Save misaka10843/e92fb8a09f2fbda6bcc4f0c915a7a0b4 to your computer and use it in GitHub Desktop.
python用临时ipv6地址更换cloudflare的域名解析
import os
import re
import requests
import json
def getIPv6Address():
output = os.popen("ipconfig /all").read()
# print(output)
result = re.findall(
r"临时 IPv6 地址. . . . . . . . . . : (([a-f0-9]{1,4}:){7}[a-f0-9]{1,4})", output, re.I)
return result[0][0]
def dns_records():
headers = {
'X-Auth-Email': '你的邮箱',
'X-Auth-Key': '你的Global API Key',
'Content-Type': 'application/json',
}
data = '{"type":"AAAA","name":"你需要替换解析的域名(如123.example.com)","content":"' + \
getIPv6Address()+'","ttl":1,"proxied":false}'
response = requests.put(
'https://api.cloudflare.com/client/v4/zones/域名ID/dns_records/解析ID', headers=headers, data=data)
success = json.loads(response.text).get('success')
if success:
print("已经成功替换啦!")
else:
print("替换失败....看看哪里填错了?或者在GitHub问问?")
if __name__ == "__main__":
dns_records()

使用前必读!

注意!您首先需要获取您的cloudflare的Global API Key Global API Key获取

然后需要获取到您的域名ID与解析ID,先打开F12,修改您需要修改的域名解析,找到如图所示的请求

点击它,并且点击预览

黄字标号1的是你的域名ID(zone_id),黄字标号2的是你的解析ID(id)

屏幕截图 2022-01-24 233113.png 大图在此qwq

将获取到的两个ID替换到python文件中即可使用!

祝你用的愉快qwq

@misaka10843
Copy link
Author

以防万一还是说一句,此py文件在python3.8进行过测试,理论支持3.0+,2.*并不知道是否能运行,请注意

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment