#定义log文件名称
$name=get-date -format 'yyyyMMddHHmmss'
#获取ipv6的地址
$ture_ip=[System.Net.Dns]::GetHostAddresses($ip) | Where-Object { $_.AddressFamily -eq 'InterNetworkV6' } | select -first 3 | Select -ExpandProperty IPAddressToString | select -last 1
#定义初始值
echo $ture_ip
$p_value = "value=" + $ture_ip
$uri_record= "https://dnsapi.cn/Record.List"
$uri_modify= "https://dnsapi.cn/Record.Modify"
$p_token = "login_token=12345,1111111111"
$p_record_line_id = "record_line_id=0"
$p_sub_domain = "sub_domain=*****"
$p_record_type = "record_type=AAAA"
$p_domain = "domain=****.****"
#获取网页返回数据并处理
$record_info=( curl.exe -X POST $uri_record -d 'login_token=12345,1111111111&format=json&domain=bosshome.top&sub_domain=**** ' | python -m json.tool | out-file -filepath D:\Myapps\Dnspod\record_info.json )
$record_ip= (Get-Content 'D:\record_info.json' | ConvertFrom-Json).records.value
echo $record_ip
$record_id= (Get-Content 'D:\record_info.json' | ConvertFrom-Json).records.id
#echo $record_id
#定义record_di$p_record_id
$p_record_id="record_id=" + $record_id
#判断ip是否修改
If( $record_ip -eq $ture_ip )
{
echo 'ip not changed'
write-output 'ip not changed' $p_value $p_record_id | out-file -filepath D:\log\$name.log
}
Else{
echo 'need change ip,please wait '
curl.exe -X POST $uri_modify `
-d $p_token `
-d $p_domain `
-d $p_record_id `
-d $p_sub_domain `
-d $p_record_type `
-d $p_record_line_id `
-d $p_value | python -m json.tool | out-file -filepath D:\update_info.json
$result_info=Get-Content 'D:\update_info.json'
#echo $result_info
$result_record_id=(Get-Content 'D:\update_info.json' | ConvertFrom-Json).record.id
If($result_record_id -eq $record_id)
{
echo 'ip updated'
write-output 'ip updated' $result_info | out-file -filepath D:\og\$name+updated.log
}
Else{
echo 'erro'
write-output 'erro' $result_info | out-file -filepath D:\log\$name+erro.log
}
}
直接贴修改的代码,关键字win10、ipv6、powershell、dnspod
参考:https://www.dnspod.cn/docs/records.html#dns
https://www.pstips.net/
https://www.cnblogs.com/jhxxb/p/13217538.html