Page 1 of 1

ip resolver an change ip if changed -need help

Posted: Tue Jul 16, 2013 1:44 am
by Ehman
Hi, can someone help me with a script that resolves a ip and only update it, if the IP changed?

#here is my current script
:local resolvedIP [:resolve "mydomaintoberesolved.com"];
/ip hotspot walled-garden ip set [find comment=mydomainthingy] dst-address $resolvedIP

so every time it updates/resolves it disrupts the connection :(

Re: ip resolver an change ip if changed -need help

Posted: Tue Jul 16, 2013 3:45 am
by SurferTim
Use two walled-garden ip entries.
/ip hotspot walled-garden ip
add dst-address=1.2.3.4 action=accept comment=currentIP
add dst-address=2.3.4.5 action=accept comment=oldIP
Then enter this script and run it. Change the domain name of course.
:local resolvedIP [:resolve www.mydomain.com];
:local currentIP [/ip hotspot walled-garden ip get [find comment=currentIP] dst-address];

:if ($resolvedIP != $currentIP) do={
  /ip hotspot walled-garden ip set [find comment=oldIP] dst-address=$currentIP;
  /ip hotspot walled-garden ip set [find comment=currentIP] dst-address=$resolvedIP;
}
It will keep the current ip and the previous ip in the walled garden in the event a client is still using the previous ip.

Re: ip resolver an change ip if changed -need help

Posted: Tue Jul 16, 2013 6:41 pm
by Ehman
thx :)