Esempio n. 1
0
}
function updateIP($hostname, $newIP, $oldIP, $awszoneid, $type = 'A', $ttl = 60)
{
    global $r53;
    $delete = $r53->prepareChange('DELETE', $hostname, $type, $ttl, $oldIP);
    $result = $r53->changeResourceRecordSets($awszoneid, $delete);
    $create = $r53->prepareChange('CREATE', $hostname, $type, $ttl, $newIP);
    $result = $r53->changeResourceRecordSets($awszoneid, $create);
}
//print_r($r53->listHostedZones());
//print_r($r53->getHostedZone($awszoneid));
$recordSet = $r53->listResourceRecordSets($awszoneid);
//print_r($recordSet['ResourceRecordSets']);
for ($i = 0; $i < count($recordSet['ResourceRecordSets']); $i++) {
    if ($recordSet['ResourceRecordSets'][$i]['Name'] == $hostname) {
        //    print_r($recordSet['ResourceRecordSets'][$i]);
        //    echo $recordSet['ResourceRecordSets'][$i]['Name'];
        $oldIP = $recordSet['ResourceRecordSets'][$i]['ResourceRecords'][0];
        $type = $recordSet['ResourceRecordSets'][$i]['Type'];
        $ttl = $recordSet['ResourceRecordSets'][$i]['TTL'];
        //    echo $oldIP;
    }
}
$newIP = getPublicIP();
if ($oldIP == $newIP) {
    //  echo "No change necessary.\n";
} else {
    echo "Updating " . $hostname . " from " . $oldIP . " to " . $newIP . "\n";
    updateIP($hostname, $newIP, $oldIP, $awszoneid);
    //  echo " done.";
}
Esempio n. 2
0
    exit;
}
//获取域名ID
$domain_id = getDomainID(DOMAIN);
if (!$domain_id) {
    echo '域名未在DNSPOD添加,请在DNSPOD添加域名。' . PHP_EOL;
    exit;
}
//获取RECORD ID
$record_id = getRecordID($domain_id, RECORD);
if (!$record_id) {
    echo '您当前还未在DNSPOD建立此record记录,请先前往DNSPOD添加记录。' . PHP_EOL;
    exit;
}
$record_ip = getRecordIP($domain_id, RECORD);
//echo '当前record ID 为'.$record_id.PHP_EOL";
echo '当前record IP 为' . $record_ip . PHP_EOL;
//获取当前的广域网IP地址
$ip = getPublicIP();
//判断获取的公网IP地址是否合法
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    echo '获取的IP地址不是合法的公网IP,获取的IP地址为:' . $ip . PHP_EOL;
    exit;
}
echo '当前广域网IP为:' . $ip . PHP_EOL;
//如果当前广域网IP和DNSPOD注册IP不一样,则修改为当前广域网IP
if ($ip != $record_ip) {
    echo '更改结果: ' . PHP_EOL . changeRecord($domain_id, $record_id, $ip, RECORD) . PHP_EOL;
} else {
    echo 'Nothing to do. ' . PHP_EOL;
}