I’m 100% new to scripting so this will probably be something stupid I’m missing. But I’m trying to get the current IP of ether1 and add it to an address list. On the address list, I’m getting the network address (e.g. 192.168.200.0/24) instead of just the IP address (192.168.200.1). Am I pulling the data from the wrong value-name?
In the standard RouterOS configurations, ether1 is often a WAN uplink, placed into the “WAN” interface list, giving you little need to specify a particular IP. Is there a good reason you can’t simply say something like in-interface-list=WAN instead?
If not, it would help if you’d describe what you’re doing with this “wan_ip” list. A better solution may occur to someone once they have all the details. Without it, this feels like an X-Y problem.
The get method should still work but only for interfaces with a single IP address, but since it is possible (and actually also common enough) to have more than one IP address on an interface, the “right” method is the “pick” one that should work in all cases.
What I don’t understand is why seemingly the “limited” command produced the network mask, it should have been either an error or an empty string.
@jaclaz
What @diamuxin wrote is,
“/ip/address/get $id address” returns string value like “192.168.88.1/24”,
so we have to strip netmask “/24” before adding it to /ip/firewall/address-list (if we don’t want to add network address to it).
And your indication is an another issue, certainly it’s a potential bug.
Of course it’s not good practice, but if the interface has exactly one address and we have confidence about it, it’s not a big matter, I think.
The OP stated that he got the network, specifically 192.168.200.0/24 instead of the expected 192.168.200.1, that’s why I was perplexed.
Now that is clear that the difference is that he got 192.168.200.1/24 while he wanted only the IP address without the /24, everything is back to normality.
Still, the difference between results of a same command depending on whether the target has one or more IP addresses - while maybe not a proper/serious bug - seems to be undocumented or poorly documented and the fact that the official help document uses the command that may fail without even a note about it doesn’t help the inexperienced people attempting to learn scripting.