ROS开启DNS服务器后,使用ROS脚本动态从服务端数据库时更新IP到ROS里,实现批量的动态DDNS,供客户使用
php脚本
<?php
header(‘Content-type: text/plain‘);
$id=filter_input(INPUT_GET,‘id‘);
echo ":global dnsadd do={
##/ip dns static remove [find regexp=\$ddns address!=\$ipaddress]
/ip dns static remove [find regexp=\$ddns]
/ip dns static add address=\$ipaddress regexp=\$ddns ttl=20s
}
";
//$dnsadd ipaddress=1.1.1.1 ddns=www.ip99.com
require_once ‘s5admin/db/db.php‘;
$sql="select publicipaddress,pppoeid,areaid from s5 where areaid=‘$id‘ order by (0+pppoeid)";
$res=mysqli_query($conn,$sql);
while($row=mysqli_fetch_row($res)) {
$qian=array(" "," ","\t","\n","\r");
$nnip=trim($row[1]);
$arrip=explode("\n",$nnip);
//echo "$row[0]$port\r\n";
foreach($arrip as $v) {
$vip=str_replace($qian, ‘‘, $v);
}
$areaid=$row[2];
//$ipstr=$row[0] . ‘ ‘ . "ip$vip" . ".os${areaid}.com\r\n";
$ipstr="\$dnsadd ipaddress=$row[0] ddns=" . "ip$vip" . ".os${areaid}.com\r\n";
echo $ipstr;
}
mysqli_close($conn);
?>
ROS脚本
{ :local nowstart 0 :local newstart 0 :local EOF true :local url "http://serverip/dns.php\?id=82" :local ipaddress "" :local ddns "" :put $url /tool fetch url=$url keep-re=yes dst-path=dns /import file=dns }
MIKROTIK ROS+PHP+MYSQL实现从数据库中配置DNS服务器
原文:https://www.cnblogs.com/ip99/p/14772420.html