扫描二维码关注官方公众号
返回列表 发布新帖

[求助/问答] 请教电信公网IP采用dnspod或者阿里云绑定顶级域名的具体操...

2954 4
发表于 2017-5-22 17:38:41 | 查看全部 阅读模式

来吧兄弟,一起玩一起讨论!

您需要 登录 才可以下载或查看,没有账号?注册

×
网上看到很多教程,但大都是针对linux的对于小白来说比较复杂,也见到有针对群辉计划任务的帖子感觉还是说的比较笼统。有没有哪位大神能系统的给讲解下利用计划任务来绑定顶级域名实现定时查询更新IP实现DDNS的具体操作步骤的啊,非常感谢!!

评论4

cdkey51Lv.3 发表于 2017-5-22 17:42:00 来自手机 | 查看全部
有相关的脚本,找找很多的。
回复 点赞

使用道具 举报

nhwnhw楼主Lv.3 发表于 2017-5-22 17:44:44 | 查看全部
确实有不少 不过本人对linux不是太了解 很多帖子上讲的很笼统。
回复 点赞

使用道具 举报

ErrLv.10 发表于 2017-5-23 01:17:48 | 查看全部
本帖最后由 Err 于 2017-5-23 01:27 编辑
  1. <?php
  2. /**
  3. * Aliyun DDNS Service
  4. * @author : zhangyunpeng
  5. * [url=home.php?mod=space&uid=31818]@date[/url]   : 2015-12-29
  6. * @email  : zyp@turbonet.cn
  7. * @website: blog.turbonet.cn
  8. * @license: Apache License, Version 2.0
  9. */
  10. /************************ Config *************************/
  11. $accessKeyId  = '';
  12. $accessSecret = '';
  13. $hostRecord   = '';/*www*/
  14. $baseDomain   = '';/*baidu.com*/
  15. $recordId     = '';/*不用填*/
  16. /*********************** End Config **********************/
  17. error_reporting(0);
  18. set_time_limit(120);
  19. $success = true;
  20. do {
  21.     $domainListConfig = array(
  22.         'Action'     => 'DescribeDomainRecords',
  23.         'DomainName' => $baseDomain,
  24.         'RRKeyWord'  => $hostRecord,
  25.     );
  26.     $domainListUrl    = ali_request_url($domainListConfig);
  27.     $domainList       = ssl_request($domainListUrl);
  28.     $domainListObject = json_decode($domainList);
  29.     if (isset($domainListObject->DomainRecords)) {
  30.         $recordId    = $domainListObject->DomainRecords->Record[0]->RecordId;
  31.         $recordValue = $domainListObject->DomainRecords->Record[0]->Value;
  32.         $success = true;
  33.         console_msg('Get the domain name record successfully.');
  34.     } else {
  35.         $success = false;
  36.         console_msg('Failed to get the domain name record, after two seconds retry.');
  37.         sleep(2);
  38.     }
  39. } while(!$success);
  40. do {
  41.     $currentIp = get_ip();
  42.     if ($currentIp == $recordValue) {
  43.         console_msg('Record match, do not modify.');
  44.         break;
  45.     }
  46.     $updateDomainConfig = array(
  47.         'Action'   => 'UpdateDomainRecord',
  48.         'RecordId' => $recordId,
  49.         'RR'       => $hostRecord,
  50.         'Type'     => 'A',
  51.         'Value'    => $currentIp,
  52.         'TTL'      => '120',
  53.     );
  54.     $updateDomainUrl    = ali_request_url($updateDomainConfig);
  55.     $updateDomain       = ssl_request($updateDomainUrl);
  56.     $updateDomainObject = json_decode($updateDomain);
  57.     if (isset($updateDomainObject->RecordId)) {
  58.         $success = true;
  59.         console_msg('Domain name change success.');
  60.     } else {
  61.         $success = false;
  62.         console_msg('Domain name change failed, after two seconds retry.');
  63.         sleep(2);
  64.     }
  65. } while(!$success);
  66. /********************** Functions *********************/
  67. function get_ip()
  68. {
  69.     $result = file_get_contents('http://ddns.oray.com/checkip');
  70.     if (!$result) {
  71.         return false;
  72.     }
  73.     $replace   = array('Current IP Check','Current IP Address',':',' ');
  74.     $ipaddress = str_replace($replace, '', strip_tags($result));
  75.     return ip2long($ipaddress) ? $ipaddress : false;
  76. }
  77. function ssl_request($url)
  78. {
  79.     $ch = curl_init();
  80.     curl_setopt($ch, CURLOPT_URL            , $url);
  81.     curl_setopt($ch, CURLOPT_HEADER         , 0);
  82.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , 2);
  83.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
  84.     curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
  85.     $response = curl_exec($ch);
  86.     curl_close($ch);
  87.     return $response;
  88. }
  89. function ali_request_url($currentConfig = array())
  90. {
  91.     global $accessKeyId, $accessSecret;
  92.     date_default_timezone_set('UTC');
  93.     $commonConfig = array(
  94.         'Format'           => 'JSON',
  95.         'Version'          => '2015-01-09',
  96.         'AccessKeyId'      => $accessKeyId,
  97.         'SignatureMethod'  => 'HMAC-SHA1',
  98.         'Timestamp'        => date("Y-m-d\TH:i:s\Z"),
  99.         'SignatureVersion' => '1.0',
  100.         'SignatureNonce'   => time().rand(),
  101.     );
  102.     $config = array_merge($commonConfig, $currentConfig);
  103.     ksort($config);
  104.     $urlParams  = http_build_query($config);
  105.     $signString = 'GET&'.urlencode('/').'&'.urlencode($urlParams);
  106.     $signResult = base64_encode(hash_hmac('sha1', $signString, $accessSecret.'&', true));
  107.     $requestUrl = 'https://dns.aliyuncs.com/?'.$urlParams.'&Signature='.$signResult;
  108.     return $requestUrl;
  109. }
  110. function console_msg($msg)
  111. {
  112.     echo 'Message: '.$msg."\n";
  113. }
  114. ?>
复制代码


另存为 aliddns.php或   名字.php
任务计划  php  /你的路径/aliddns.php
回复 点赞

使用道具 举报

nhwnhw楼主Lv.3 发表于 2017-5-23 17:06:54 | 查看全部
非常感谢 我试试
回复 点赞

使用道具 举报

回复

懒得打字嘛,点击右侧快捷回复 【本站酷狼4T,750元】
您需要登录后才可以回帖 登录 | 注册

本版积分规则

淘宝小店

邀请码

VIP会员

微信客服

公众号

微信群

投诉/建议联系

support@gebi1.cn

未经授权禁止转载,复制和建立镜像,
如有违反,追究法律责任
  • 关注公众号
  • 添加微信客服
Copyright © 2001-2024 隔壁网 版权所有 All Rights Reserved. 粤ICP备14056481号-1
关灯 在本版发帖
扫一扫添加微信客服
返回顶部
快速回复 返回顶部 返回列表