-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresslist-ip-update.rsc
executable file
·49 lines (41 loc) · 1.69 KB
/
addresslist-ip-update.rsc
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
#!rsc by RouterOS
# RouterOS script: addresslist-ip-update
#
# update dinamic ips of address list if changed
# https://github.com/martindb/routeros/blob/main/doc/addresslist-ip-update.md
:local 0 "addresslist-ip-update";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global SendNotification;
:global SymbolForNotification;
:global LogPrint;
:global ParseKeyValueStore;
:global IsFullyConnected;
:if ([ $IsFullyConnected ] = false) do={
$LogPrint debug $0 ("System is not fully connected, not updating.");
:return false;
}
$LogPrint debug $0 "Init";
:foreach ListEntry in=[/ip/firewall/address-list/find where comment~"fqdn=" !disabled] do={
:local ListEntryVal [ /ip/firewall/address-list/get $ListEntry ];
:local Comment [ $ParseKeyValueStore ($ListEntryVal->"comment") ];
:local Fqdn ($Comment->"fqdn");
:local Notify ($Comment->"notify");
:local OldIp ($ListEntryVal->"address");
$LogPrint debug $0 ("Fqdn: $Fqdn - OldIp: $OldIp - Notify: $Notify");
:do {
:local NewIp [:resolve $Fqdn]
$LogPrint debug $0 ("Fqdn: $Fqdn - OldIp: $OldIp - NewIp: $NewIp");
:if ($NewIp != $OldIp) do={
/ip/firewall/address-list/set $ListEntry address=$NewIp
$LogPrint info $0 ("$Fqdn IP address changed: $OldIp -> $NewIp");
:if ($Notify = true) do={
$SendNotification ([$SymbolForNotification "warning-sign"] . "$Fqdn IP updated") ("$0: $Fqdn IP address changed: $OldIp -> $NewIp");
}
}
} on-error={
$LogPrint warning $0 ("Unable to resolve $Fqdn");
$SendNotification ([$SymbolForNotification "cross-mark"] . "Unable to resolve $Fqdn") ("$0: can't update IP of $Fqdn");
}
}
$LogPrint debug $0 "End";