自己写的dnspod php设置ip的脚本

分享一个自己写的dnspod php设置ip的脚本.
token获取见 https://support.dnspod.cn/Kb/showarticle/tsid/227/
参数传递见 http://www.dnspod.cn/docs/batch.html#batch-record-modify
脚本如下.

<?php
/*
 * 44472@163.com
 */
ini_set('display_errors', 'off');
error_reporting(0);

$CACHE_FILE = '/tmp/dnspod.cache.log'; //$CACHE_FILE = false; #变量为false代表不缓存每次都更新

$CONFIG = array(
	'login_token'=>'',
	'domain_id'=>'',
	'record_id'=>'',
	'sub_domain'=>'www',
	'record_type'=>'A',
	'record_line'=>'默认',
	'format'=>'json',
);

$content = (get('http://ip.taobao.com/service/getIpInfo2.php?ip=myip'));
$content and $content=json_decode($content,true) or die('Ip Api Errors');
$ip = $content['data']['ip'] or die('Ip Api Errors');

if($CACHE_FILE){
	if(file_get_contents($CACHE_FILE)==$ip){
		die('No Change');
	}
	file_put_contents($CACHE_FILE,$ip);
}

$CONFIG['value'] = $ip;
echo post('https://dnsapi.cn/Record.Modify',$CONFIG);




/// tools function
function get($uri)
{
    $ch = curl_init ();
    curl_setopt ($ch, CURLOPT_URL,$uri);
    curl_setopt ($ch, CURLOPT_HEADER,0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
    $return = curl_exec ( $ch );
    curl_close ( $ch );
    return $return;
}
function post($uri,$data)
{
    is_array($data) and $data=http_build_query($data);
    var_dump($data);
    $ch = curl_init ();
    curl_setopt ($ch, CURLOPT_URL,$uri);
    curl_setopt ($ch, CURLOPT_POST,1);
    curl_setopt ($ch, CURLOPT_HEADER,0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS,$data);
    $return = curl_exec ( $ch );
    curl_close ( $ch );
    return $return;
}

发表评论

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

Captcha Code