Dnspod Ddns PHP AutoUPdate Script

#!/usr/bin/env php
<?php

$domain = “xxxx.com”;
$subdomain = “home”;

$user_id = 6**2;
$dnspod_id = 1**7;
$dnspod_tocken = “97641****21ea8a”;
$dnspod_url = “http://dnsapi.cn/”;
$dnspod_common = [‘login_token’=>’14***7,97641****21ea8a’,’format’=>’json’,’lang’=>’en’];


function posturl($url,$data){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return json_decode($output,true);
}

function geturl($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
return $output;
}

function get_ip(){
$real_ip = trim(geturl(“https://www.**.com/ip.php”));
return $real_ip;
}

$real_ip = get_ip();

//get domain_id;
$domainid_url = “https://dnsapi.cn/Domain.Info”;
$postData = array_merge($dnspod_common,[‘domain’=>$domain]);
$domaininfo = posturl($domainid_url,$postData);
$domain_id = $domaininfo[“domain”][“id”];
$postData = [];


//get record_id
$recordid_url = “https://dnsapi.cn/Record.List”;
$postData = array_merge($dnspod_common,[‘domain_id’=>$domain_id,’sub_domain’=>$subdomain]);
$recordinfo = posturl($recordid_url,$postData);
$record_id = $recordinfo[‘records’][0][‘id’];
$postData = [];
//

//update ddns record.
$ddns_url = “https://dnsapi.cn/Record.Ddns”;
$postData = array_merge($dnspod_common,[‘domain’=>$domain,’sub_domain’=>$subdomain,’record_id’=>$record_id,’record_line’=>’默认’,’value’=>$real_ip]);
$ddnsinfo = posturl($ddns_url,$postData);
?>

//update ddns record.$ddns_url = “https://dnsapi.cn/Record.Ddns”; $postData = array_merge($dnspod_common,[‘domain’=>$domain,’sub_domain’=>$subdomain,’record_id’=>$record_id,’record_line’=>’默认’,’value’=>$real_ip]);$ddnsinfo = posturl($ddns_url,$postData);?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注