Scripting is not my thing, but I’ll guess sometimes I need it… ![]()
I want a domain name resolved by a script to update the IP address on a regular basis.
It must be somewhere on this forum/wiki but spend 2 hours without finding it. Tried several examples but could not get it to work.
What I want:
Only (my) SIP server mentioned by name in Voip-gateway’s of clients need to get prioritized.
So need to write mangle and queue for that traffic. But mangle can only work with IP, so need somewhere to get the IP of the sip server. I think best is to get it from dst-address list.
I make a address-list listing for “mySIPsrvr.com” with IP address x.x.x.x
Now I need a script that regularly (scheduler) checks and if of need, updates the address-list for that “mySIPsrvr” listing.
Script that I tried (but fails):
:local resolvedIP [:resolve “mySIPsrvr.com”];
:local sipsrvrID [/ip firewall address-list find name=“mySIPsrvr.com”];
:local currentIP [/ip firewall address-list get $sipsrvrID address];
:if ($resolvedIP != $currentIP) do={
/ip firewall address-list set 0 address=$resolvedIP;
/log info “sipsrvr ip updated”;
}
}
++++++++++
- How to test and debug the script working? I tried log “script debug” mode but nothing happens. But the script counts…
- How to find an address-list listing? I try “find” or “get” or “print” commando in CLI but I get not what I want…
I suspect the line:
:local sipsrvrID [/ip firewall address-list find name="mySIPsrvr.com"];
is wrong? Can it really find the address list listing with that name?
If it is wrong, how to do it right?
The
:if ($resolvedIP != $currentIP) do={
/ip firewall address-list set 0 address=$resolvedIP;
is also not right. It actually needs to set the IP for the listing with the name “mySIPsrvr.com” because the line number can change (and is not real in this case).
Some help is really appreciated (karma!)