记录使用powershell更新dnspod

  #定义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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值