} /* 设置默认IP以及默认网卡 */ $default_ip = $nic_a_ip ? $nic_a_ip : $nic_b_ip; $default_interface = $nic_a_ip ? $nic_a_lan_ip : $nic_b_lan_ip; define('NETINTERFACE', $default_interface); /* 设置线路冗余 */ if (!$nic_a_ip) { $nic_a_ip = $default_ip; } if (!$nic_b_ip) { $nic_b_ip = $default_ip; } /* 从DNSPod获取旧的设置 */ $nic_a_ip_old = dnspod_get_ip($nic_a_record_id); $nic_b_ip_old = dnspod_get_ip($nic_b_record_id); if (empty($nic_a_ip_old) && empty($nic_b_ip_old)) { exit("Can not connect to DNSPod API"); } /* 更新第一条线路IP记录 */ if ($nic_a_ip != $nic_a_ip_old) { echo "Update Line A record from {$nic_a_ip_old} to {$nic_a_ip} ..."; $result = dnspod_update_ip($nic_a_record_id, $nic_a_ip, $nic_a_line); echo $result ? "Successed\r\n" : "Failed\r\n"; } /* 更新第二条线路IP记录 */ if ($nic_b_ip != $nic_b_ip_old) { echo "Update Line B record from {$nic_b_ip_old} to {$nic_b_ip} ..."; $result = dnspod_update_ip($nic_b_record_id, $nic_b_ip, $nic_b_line); echo $result ? "Successed\r\n" : "Failed\r\n"; } echo "All done.";
//更新默认线路IP记录 if ($default_ip != $default_ip_old) { echo "Update default record from {$default_ip_old} to {$default_ip} ... "; $result = dnspod_update_ip($record_id[0], $default_ip, '默认'); echo $result ? "Successed\r\n" : "Failed\r\n"; } //更新电信线路IP记录 if ($dx_ip != $dx_ip_old) { echo "Update Telecom record from {$dx_ip_old} to {$dx_ip} ... "; $result = dnspod_update_ip($record_id[1], $dx_ip, '电信'); echo $result ? "Successed\r\n" : "Failed\r\n"; } //更新联通线路IP记录 if ($lt_ip != $lt_ip_old) { echo "Update Unicom record from {$lt_ip_old} to {$lt_ip} ... "; $result = dnspod_update_ip($record_id[2], $lt_ip, '联通'); echo $result ? "Successed\r\n" : "Failed\r\n"; } echo "All done."; //指定网卡获取IP函数 //输入:网卡的内网静态IP地址 //输出:网卡的外网地址或者FALSE function get_ip($interface) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, IP_API); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_INTERFACE, $interface); curl_setopt($ch, CURLOPT_USERAGENT, 'PHP DDNS Client/0.3 (vibbow@gmail.com)'); $result = curl_exec($ch);