MIKROTIK ROS+PHP+MYSQL实现从数据库中配置DNS服务器

ROS开启DNS服务器后,使用ROS脚本动态从服务端数据库时更新IP到ROS里,实现批量的动态DDNS,供客户使用

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
<?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






}
复制代码

 

posted @   嗷嗷鹿鸣[VX|dshoub]  阅读(339)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示