请教电信公网IP采用dnspod或者阿里云绑定顶级域名的具体操...
网上看到很多教程,但大都是针对linux的对于小白来说比较复杂,也见到有针对群辉计划任务的帖子感觉还是说的比较笼统。有没有哪位大神能系统的给讲解下利用计划任务来绑定顶级域名实现定时查询更新IP实现DDNS的具体操作步骤的啊,非常感谢!!有相关的脚本,找找很多的。 确实有不少 不过本人对linux不是太了解 很多帖子上讲的很笼统。 本帖最后由 Err 于 2017-5-23 01:27 编辑
<?php
/**
* Aliyun DDNS Service
* @author : zhangyunpeng
* @date : 2015-12-29
* @email: zyp@turbonet.cn
* @website: blog.turbonet.cn
* @license: Apache License, Version 2.0
*/
/************************ Config *************************/
$accessKeyId= '';
$accessSecret = '';
$hostRecord = '';/*www*/
$baseDomain = '';/*baidu.com*/
$recordId = '';/*不用填*/
/*********************** End Config **********************/
error_reporting(0);
set_time_limit(120);
$success = true;
do {
$domainListConfig = array(
'Action' => 'DescribeDomainRecords',
'DomainName' => $baseDomain,
'RRKeyWord'=> $hostRecord,
);
$domainListUrl = ali_request_url($domainListConfig);
$domainList = ssl_request($domainListUrl);
$domainListObject = json_decode($domainList);
if (isset($domainListObject->DomainRecords)) {
$recordId = $domainListObject->DomainRecords->Record->RecordId;
$recordValue = $domainListObject->DomainRecords->Record->Value;
$success = true;
console_msg('Get the domain name record successfully.');
} else {
$success = false;
console_msg('Failed to get the domain name record, after two seconds retry.');
sleep(2);
}
} while(!$success);
do {
$currentIp = get_ip();
if ($currentIp == $recordValue) {
console_msg('Record match, do not modify.');
break;
}
$updateDomainConfig = array(
'Action' => 'UpdateDomainRecord',
'RecordId' => $recordId,
'RR' => $hostRecord,
'Type' => 'A',
'Value' => $currentIp,
'TTL' => '120',
);
$updateDomainUrl = ali_request_url($updateDomainConfig);
$updateDomain = ssl_request($updateDomainUrl);
$updateDomainObject = json_decode($updateDomain);
if (isset($updateDomainObject->RecordId)) {
$success = true;
console_msg('Domain name change success.');
} else {
$success = false;
console_msg('Domain name change failed, after two seconds retry.');
sleep(2);
}
} while(!$success);
/********************** Functions *********************/
function get_ip()
{
$result = file_get_contents('http://ddns.oray.com/checkip');
if (!$result) {
return false;
}
$replace = array('Current IP Check','Current IP Address',':',' ');
$ipaddress = str_replace($replace, '', strip_tags($result));
return ip2long($ipaddress) ? $ipaddress : false;
}
function ssl_request($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
function ali_request_url($currentConfig = array())
{
global $accessKeyId, $accessSecret;
date_default_timezone_set('UTC');
$commonConfig = array(
'Format' => 'JSON',
'Version' => '2015-01-09',
'AccessKeyId' => $accessKeyId,
'SignatureMethod'=> 'HMAC-SHA1',
'Timestamp' => date("Y-m-d\TH:i:s\Z"),
'SignatureVersion' => '1.0',
'SignatureNonce' => time().rand(),
);
$config = array_merge($commonConfig, $currentConfig);
ksort($config);
$urlParams= http_build_query($config);
$signString = 'GET&'.urlencode('/').'&'.urlencode($urlParams);
$signResult = base64_encode(hash_hmac('sha1', $signString, $accessSecret.'&', true));
$requestUrl = 'https://dns.aliyuncs.com/?'.$urlParams.'&Signature='.$signResult;
return $requestUrl;
}
function console_msg($msg)
{
echo 'Message: '.$msg."\n";
}
?>
另存为 aliddns.php或 名字.php
任务计划php/你的路径/aliddns.php 非常感谢 我试试
页:
[1]