Community discussions

MUM Europe 2020
 
WirelessRudy
Forum Guru
Forum Guru
Topic Author
Posts: 3089
Joined: Tue Aug 08, 2006 5:54 pm
Location: Spain

Please assist on name resolving script for address list

Mon Apr 02, 2012 2:36 pm

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";
}

}

++++++++++
1. How to test and debug the script working? I tried log "script debug" mode but nothing happens. But the script counts...
2. 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!)
Show your appreciation of this post by giving me Karma! Thanks.

Rudy R. Puister

WISP operator based on MT routerboard & ROS.
 
ditonet
Forum Veteran
Forum Veteran
Posts: 841
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: Please assist on name resolving script for address list

Mon Apr 02, 2012 3:11 pm

Add 'my_SIP_server' comment to address-list entry.
:local resolvedIP [:resolve "mySIPsrvr.com"];
:local currentIP [/ip firewall address-list get [find comment="my_SIP_server"] address];
:if ($resolvedIP != $currentIP) do={
   /ip firewall address-list set [find comment="my_SIP_server"] address=$resolvedIP;
}
HTH,
Grzegorz | MTCNA, MTCRE, MTCSE | konsultacje MikroTik Warszawa
It is a book about a Spanish guy called Manual. You should read it. - Dilbert

Who is online

Users browsing this forum: No registered users and 4 guests