Is there any way of building a script, or something, to check the ip of an certain interface in mikrotik, and update it to a adress list?
For Nat rules with a dynamic ip?
I tried the In-interface, with no luck
Is there any way of building a script, or something, to check the ip of an certain interface in mikrotik, and update it to a adress list?
For Nat rules with a dynamic ip?
I tried the In-interface, with no luck
This should get you started…
:global currentIP;
:local tmpIP [/ip address get [find interface="WAN"] address];
:local myIP [:pick $tmpIP 0 [:find $tmpIP "/"]];
:if ($myIP != $currentIP) do={
:log info "WAN IP address changed from $currentIP to $myIP"
:foreach rule in=[/ip firewall nat find dst-address=$currentIP] do={
/ip firewall nat set $rule dst-address=$myIP;
}
:set currentIP $myIP;
/tool fetch url="http://url.to.server/page?args&stuff"
}
Thanks troy!
Now when I run that script, it logs and seays my WAN ip changed to x.x.x.x
But when I check address list, there is no IP there.
Should I create an address list first?
This part of the script is what updates the NAT rules:
:foreach rule in=[/ip firewall nat find dst-address=$currentIP] do={
/ip firewall nat set $rule dst-address=$myIP;
}
To update an address list, you’ll need to rewrite this to find and update appropriate entries in your address list.
It will not create anything new, and will do nothing if the ‘find’ filter doesn’t actually find anything.
The in-interface works. You better post your /ip firewall nat and /ip address to see what could be wrong.
Thanks, I got it working with in Interface