代码拉取完成,页面将自动刷新
<?php
/**
* Namesilo DDNS
* SSRPanel 2018/12/15
* Usage:Add `crontab` Command:`* * * * * php /www/wwwroot/ddns_namesilo.php`
*/
class namesilo
{
private $apiKey;
private $domain;
private $rrhost;
function __construct()
{
$this->apiKey = 'c8082318267c813f91b36111'; // set your namesilo api key
$this->domain = 'ssrpanel.com'; // set your domain
$this->rrhost = 'hk'; // set your sub domain
}
function ddns()
{
$ip = $this->checkIP();
if (false === $ip) {
$this->log("IP NOT CHANGED");
exit();
}
$recordList = $this->dnsListRecords();
$rrid = '';
foreach ($recordList['reply']['resource_record'] as $vo) {
if ($vo['host'] == $this->rrhost . '.' . $this->domain) {
$rrid = $vo['record_id'];
break;
}
}
$this->log($rrid);
if ($rrid) {
$this->dnsUpdateRecord($rrid, $this->rrhost, $ip);
}
exit();
}
function dnsListRecords()
{
$query = [
'domain' => $this->domain
];
return $this->send('dnsListRecords', $query);
}
function dnsUpdateRecord($rrid, $rrhost, $rrvalue, $ttl = 7207)
{
$query = [
'domain' => $this->domain,
'rrid' => $rrid,
'rrhost' => $rrhost,
'rrvalue' => $rrvalue,
'rrttl' => $ttl
];
return $this->send('dnsUpdateRecord', $query);
}
function getIP()
{
$result = $this->curl('http://ip.taobao.com/service/getIpInfo.php?ip=myip');
$result = json_decode($result, true);
return $result['data']['ip'];
}
function checkIP()
{
$nowIP = $this->getIP();
$file = dirname(__FILE__) . '/ddns_namesilo.ip';
$oldIP = file_get_contents($file);
if ($nowIP == $oldIP) {
return false;
}
file_put_contents($file, $nowIP);
return $nowIP;
}
function send($operation, $data = [])
{
$params = [
'version' => 1,
'type' => 'xml',
'key' => $this->apiKey
];
$query = array_merge($params, $data);
$result = $this->curl('https://www.namesilo.com/api/' . $operation . '?' . http_build_query($query));
$result = $this->xmlToArray($result);
$this->log($result);
return $result;
}
function log($data)
{
$data = is_array($data) ? var_export($data, true) : $data;
$file = dirname(__FILE__) . '/ddns_namesilo.log';
file_put_contents($file, $data . "\r\n", FILE_APPEND);
}
function xmlToArray($xml)
{
libxml_disable_entity_loader(true);
$result = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $result;
}
function curl($url, $data = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
if ($data) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
$namesilo = new namesilo();
$dnsListRecords = $namesilo->ddns();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。