-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.php
54 lines (43 loc) · 1.01 KB
/
dns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require_once dirname(__FILE__).'/DDNS.php';
$accessKeyId = "YourAliyunAccessKeyId";
$accessKeySecret = 'YourAliyunAccessKeySecret';
$myDomainName = 'YourDomainName';
/**
* Get localhost IP
*
* @param void
* @return array $data
*/
function getLocalIp()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://[2001:470:1:18::223:250]');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$data = curl_exec($curl);
curl_close($curl);
return json_decode($data, true);
}
$ddns = new DDns($accessKeyId, $accessKeySecret);
$params = [
'DomainName' => $myDomainName,
'Prefix' => 'ddns',
'Type' => 'AAAA',
];
$res = $ddns->getRecord($params);
if (!is_null($res)) {
$recordId = $res['RecordId'];
} else {
echo "not found";die;
}
$resInfo = getLocalIp();
$localIp = $resInfo['ip'];
$query = [
'RecordId' => $recordId,
'RR' => 'ddns',
'Type' => 'AAAA',
'Value' => $localIp,
];
$res = $ddns->updateRecord($query);
var_dump($res);