Mikrotik-ROS路由DDNS脚本解析noip 3322 Oray

作者 : 七界传说 发布时间: 2020-04-7 文章热度:6.55K 共7277个字,阅读需19分钟。

目 录

Mikrotik-ROS路由DDNS脚本解析noip 3322 Oray-七界传说丨关注分享网络、硬件、维护、游戏、主题、虚拟化、软件分享!

一丶DDNS for noip

访脚本的主要功能是更新当前IP、DDNS更新回传信息等

方法如下;

1、在/System Script下添加如下脚本内容

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#定义 no.ip 相关设定,以下自行修改:
#============================================================
:local DDNSUser "no-ip帐号"
:local DDNSPassword "no-ip密码"
:local DDNSHost "申请的no-ip地址"
#============================================================
#以下程式如不了解,建议不要修改:
#------------------------------------------------------------------------------------------
#定义 IP 变量
:local DDNSIP
:global DDNSLastIP

#定义变量默认值
:if ([ :typeof $DDNSLastIP ] = nil ) do={ $DDNSLastIP "0.0.0.0" }

#利用HTTP查询Public IP
/tool fetch address=checkip.dyndns.com src-path=/ mode=http dst-path=("PublicIP");
:delay 1;

#读取档案
:set DDNSIP [/file get PublicIP contents];
:set DDNSIP [:pick $DDNSIP 0 [:find $DDNSIP ""]];
:set DDNSIP [:pick $DDNSIP ([:find $DDNSIP ":"]+2) 100];

#删除档案
/file remove PublicIP;

#判断是否要更新 IP
:if ([ :typeof $DDNSIP ] = nil ) do={
:log error ("DDNS no.ip: 网络未取得 IP 位址")
} else={
:if ($DDNSIP != $DDNSLastIP) do={

# 更新 DDNS IP
:local url "/nic/update?hostname=$DDNSHost&myip=$DDNSIP"
/tool fetch address=dynupdate.no-ip.com src-path=$url mode=http user=$DDNSUser password=$DDNSPassword dst-path=("DDNS_no_ip")
:delay 1

# 档案内容
:local filestr [ /file get "DDNS_no_ip" contents];

# 删除档案
:local filename [ /file find name="DDNS_no_ip"];
/file remove $filename

# 变更是否成功
:if ( [ :find $filestr "good"] = "0" || [ :find $filestr "nochg"] = "0" ) do={
:log warning ("DDNS no.ip: 网络更新 IP 位址 " . $DDNSIP)
:set DDNSLastIP $DDNSIP
} else={
:log error ("DDNS no.ip: 网络更新 IP 位址失败 " . $DDNSIP)
}
}
}

脚本名称命名为noip

2、在/System Scheduler下添加一个脚本定时,名称为noip,内容为noip,执行时间为10分钟(时间可自定义)

注意:单线单拨可用

二丶DDNS for 3322

访脚本的主要功能是,3322 DDNS更新

方法如下;

1、在/System Script下添加如下脚本内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
:local ednsuser "user"
:local ednspass "password"
:local ednshost "xxx.3322.org"
:local ednsinterface "pppoe-out1"
:local members "http://members.3322.org/dyndns ... ot%3B
:local members "http://members.dyndns.org/nic/update?"
:local status
:local status [/interface get [/interface find name=$ednsinterface] running]
:if ($status!=false) do={
:local ednslastip [:resolve $ednshost]
:if ([ :typeof $ednslastip ] = nil ) do={ :local ednslastip "0" }
:local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
:local ednsip [:pick $ednsiph 0 [:find $ednsiph "/"]]
:local ednsstr "&hostname=$ednshost&myip=$ednsip"
:if ($ednslastip != $ednsip) do={/tool fetch url=($members . $ednsstr) mode=http user=$ednsuser password=$ednspass dst-path=$ednshost
:delay 2
:local result [/file get $ednshost contents]
:log info ($ednshost . " " .$result)
/file remove $ednshost ;
}
}

脚本名称命名为3322

2、在/System Scheduler下添加一个脚本定时,名称为3322,内容为3322,执行时间为10分钟(时间可自定义)

注意:单线单拨可用

三丶DDNS for Oray

访脚本的主要功能是,检测pppoe-out1的IP是否有变动,没变动不执行,变动就执行,执行后会把ROS设备的基本信息发送到邮箱。(路由型号、系统版本、当前IP、DDNS更新回传信息ROS自带DDNS名称等)

方法如下;

1、在/System Script下添加如下脚本内容

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
32
33
34
35
36
37
38
39
40
{
local ipaddr
local server "http://ddns.oray.com"
local domain "xinok.cn,www.xinok.cn"
local users "user"
local paswd "password"
local logname "ddns.log"
local pppoename "pppoe-out1"
local smtps "smtp.qq.com"
local ports "25"
local Mailings "user@qq.com"
local pass "password"
local recipient "user@qq.com"
local Collection "user@qq.com"
local Contents "Is your latest public IP address:"
local Themes "ros-ddns-info"
local content "Following your RouterOS with the latest info"
local smtp [:resolve $smtps]
global lastip
global rosversion ("Your Router Version is MikroTik v" . [/system resource get version] )
global rosboard ("Your Router Board is " . [/system resource get board] )
global dnsname ("Your Router dnsname is " . [/ip cloud get dns] )
:set ipaddr [/ip address get [/ip address find interface=$pppoename] address]
:set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)]
:if ($ipaddr != $lastip) do={
:set lastip $ipaddr
local par "/ph/update?&hostname=$domain&myip=$ipaddr"
/tool fetch url=($server . $par) mode=http user=$users password=$paswd keep-result=yes
dst-path=$logname
:local logcontent [ /file get $logname contents];
/file remove [/file find name=$logname]
:local ddnsinfo "DDNS update return value is $logcontent"
/tool e-mail set address=$smtp port=$ports from=$Collection user=$Collection password=$pass
:log warning "DDNS: get wan ip from $pppoename:$ipaddr"
:log warning "DDNS: has request from ddns:$logcontent"
/tool e-mail send to=$recipient from=$Collection subject=$Themes body=("$contentn$rosboardn$rosversionn$Contents$lastipn$ddnsinfon$dnsname")
:log warning "DDNS: Sends current info to Email:$Collection"
} else={
}
}
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
32
33
34
35
36
37
38
39
40
{
local ipaddr
local server "http://ddns.oray.com"
local domain "xinok.cn,www.xinok.cn"
local users "user"
local paswd "password"
local logname "ddns.log"
local pppoename "pppoe-out1"
local smtps "smtp.qq.com"
local ports "25"
local Mailings "user@qq.com"
local pass "password"
local recipient "user@qq.com"
local Collection "user@qq.com"
local Contents "Is your latest public IP address:"
local Themes "ros-ddns-info"
local content "Following your RouterOS with the latest info"
local smtp [:resolve $smtps]
global lastip
global rosversion ("Your Router Version is MikroTik v" . [/system resource get version] )
global rosboard ("Your Router Board is " . [/system resource get board] )
global dnsname ("Your Router dnsname is " . [/ip cloud get dns] )
:set ipaddr [/ip address get [/ip address find interface=$pppoename] address]
:set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)]
:if ($ipaddr != $lastip) do={
:set lastip $ipaddr
local par "/ph/update?&hostname=$domain&myip=$ipaddr"
/tool fetch url=($server . $par) mode=http user=$users password=$paswd keep-result=yes
dst-path=$logname
:local logcontent [ /file get $logname contents];
/file remove [/file find name=$logname]
:local ddnsinfo "DDNS update return value is $logcontent"
/tool e-mail set address=$smtp port=$ports from=$Collection user=$Collection password=$pass
:log warning "DDNS: get wan ip from $pppoename:$ipaddr"
:log warning "DDNS: has request from ddns:$logcontent"
/tool e-mail send to=$recipient from=$Collection subject=$Themes body=("$contentn$rosboardn$rosversionn$Contents$lastipn$ddnsinfon$dnsname")
:log warning "DDNS: Sends current info to Email:$Collection"
} else={
}
}

脚本名称命名为OrayDDNS

2、在/System Scheduler下添加一个脚本定时,名称为OrayDDNS,内容为OrayDDNS,执行时间为3分钟(时间可自定义)

注意:单线单拨可用

四丶自动备份到ftp

访脚本的主要功能是,将备份文件备份到ftp空间

方法如下;

1、在/System Script下添加如下脚本内容

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#自动备份到FTP

:local saveUserDb true; # 是否保存用户数据库转储
:local saveSysBackup true; # 是否保存整个系统备份
:local encryptSysBackup false; # 是否将系统备份(RouterOS的6.13及更高版本)加密
:local saveRawExport true; # 无论是出口整体配置为纯文本.RSC脚本

:local myFtp "ftpserver.tld" # FTP服务器地址
:local myFtpPort 21 # FTP服务器端口

:local myFtpUser "my-mikrotik" # FTP用户名
:local myFtpPass "SecurePassword" # FTP密码

:local ts [/system clock get time]
:set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])

:local ds [/system clock get date]
:set ds ([:pick $ds 7 11].[:pick $ds 0 3].[:pick $ds 4 6])

:local fname ("/BACKUP-".[/system identity get name]."-".$ds."-".$ts)

:if ($saveUserDb) do={
/tool user-manager database save name=($fname.".umb")
:log warning ("User Manager 数据库备份完成");
}

:if ($saveSysBackup) do={
:if ($encryptSysBackup) do={
/system backup save name=($fname.".backup");
}
else={
/system backup save name=($fname.".backup") dont-encrypt;
}
:log warning ("系统备份完成");
}

if ($saveRawExport) do={
/export file=($fname.".rsc")
:log warning ("原配置脚本导出rsc文件完成");
}

:if ($saveUserDb) do={
/tool fetch address=$myFtp port=$myFtpPort src-path=($fname.".umb") user=$myFtpUser mode=ftp password=$myFtpPass dst-path=($fname.".umb") upload=yes
}

:if ($saveSysBackup) do={
/tool fetch address=$myFtp port=$myFtpPort src-path=($fname.".backup") user=$myFtpUser mode=ftp password=$myFtpPass dst-path=($fname.".backup") upload=yes
}

:if ($saveRawExport) do={
/tool fetch address=$myFtp port=$myFtpPort src-path=($fname.".rsc") user=$myFtpUser mode=ftp password=$myFtpPass dst-path=($fname.".rsc") upload=yes
}

:delay 5s;

:foreach i in=[/file find] do={:if ([:typeof [:find [/file get $i name] "BACKUP-"]]!="nil") do={/file remove $i}}
:log warning (成功删除临时备份文件")
:log warning (自动备份成功完成")

脚本名称命名为autoftp

2、在/System Scheduler下添加一个脚本定时,名称为autoftp,内容为autoftp,执行时间为1天(时间可自定义)

代码引自网络资源

常见问题FAQ

免费下载或者VIP会员专享资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。

发表评论

20
+2072天安全运行
主题分享
0
+0篇本周更新
更新我快乐

VIP免费下载全站资源

立即了解

本站支持IPv6访问 本站支持SSL安全访问

站点地图