MIKROTIKROS+PHP+MYSQL实现从数据库中配置DNS服务器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MIKROTIKROS+PHP+MYSQL实现从数据库中配置DNS服务器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=
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
}。