in this script i scan all the interfaces that have name "WANxxx" like WAN1, WAN2, and then obtain it's ip address, then put that ip in an array, make it global and later run script again to check if any has changed, it works fine, but i have a problem, when some interface has no ip address, the script it´s broken and aborted in the line ":set currip [/ip address get [find interface="$ifname"] address];", the problem is when some interface has no ip, this happens frequently when the DSL goes down and the ISP dhcp server cant be reached.
somebody have any idea of how can bypass this problem? any other solution? thanks
Code: Select all
:global currentifnames;
:global currentips;
:global arraycurrentips;
:local arraynewips;
:local arraynewifnames;
:local newips;
:local newifnames;
:local iface;
:local ifname;
:local currip;
:log info "Checking interfaces.";
:foreach iface in=[/interface ethernet find name~"wan" disabled=no ] do={
:set ifname [ /interface ethernet get $iface name ];
:set newifnames ($newifnames, $ifname);
:log info $newifnames;
:set currip [/ip address get [find interface="$ifname"] address];
:set newips ($newips, $currip);
:log info $newips;
}
:set arraynewifnames [:toarray $newifnames];
:set arraynewips [:toarray $newips];