海运的博客

dnspod php api ddns

发布时间:February 18, 2018 // 分类: // No Comments

<?php
ini_set('date.timezone','Asia/Shanghai');
if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
  $ip = $_SERVER['REMOTE_ADDR'];
  $name =  $_REQUEST['id'];
  $token = "abdeafaaaa";
  $value = getid($name, $token);
  if ($value) {
    list($id, $old_ip) = explode('--', $value);
    if ($old_ip && $old_ip != $ip) {
      modip($ip, $id, $name, $token);
    } else {
      echo $old_ip.PHP_EOL;
    }
  }
}

function modip($ip, $id, $name, $token) {
  $url = "https://dnsapi.cn/Record.Modify";
  $post_data = "login_token={$token}&format=json&domain=haiyun.me&record_id={$id}&value={$ip}&record_type=A&record_line_id=0&sub_domain={$name}";
  $data = post($url, $post_data);
  $data = json_decode($data, 1);
  //var_dump($data);
  if ($data['status']['code'] == 1) {
    echo "Action completed successful".PHP_EOL;
  } else {
    echo $data['status']['message'].PHP_EOL;
  }
}

function getid($name, $token) {
  $url = "https://dnsapi.cn/Record.List";
  $post_data = "login_token={$token}&format=json&domain=haiyun.me";
  $data = post($url, $post_data);    
  $data = json_decode($data, 1);  
  foreach ($data["records"] as $value) {
    if ($value['name'] == $name) {
      return $value['id'].'--'.$value['value'];
    }
  }
  return "";
}

function post($url, $post_data) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0');
  curl_setopt($ch,CURLOPT_POST, 1);
  curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
?>

shell版本:
https://www.haiyun.me/archives/1305.html

标签:ddns, dnspod

评论已关闭

分类
最新文章
最近回复
  • 海运: 正常情况下编译整个内核执行make menuconfig后就不会出现此提示,当单独编译单个模块...
  • oijq: 就是用的armbian的配置文件哈,按你的教程做的,在执行make LOCALVERSION=...
  • 海运: 使用armbian的配置文件,其它添加或修改自己懂的部分,不懂的就不要碰了。
  • oijq: 编译时这些选项全部选Y吗?Actions Semi Platforms (ARCH_ACTIO...
  • 海运: n1编译bbr内核模块参考这个:https://www.haiyun.me/archives/...
  • jiqz: make M=net/ipv4/ CONFIG_TCP_CONG_BBR=m modules编...
  • ruralhunter: 哦,文档里应该是对的,是.config
  • ruralhunter: cp /mnt/boot/config-4.18.7-aml-s9xxx .config这里应...
  • 海运: 你是编译不成功呢?还是编译后不能运行呢?还是运行后不能访问web界面呢?
  • 白墨: 可能不清楚就是编译安装后启动后访问不了web界面