Get List of All Usable Ips

Hi,

I’m looking for a command to give me back all the usable ips in a range.i.e
if i have a 192.168.29.1/30 in ip addresses
thus,
network 192.168.29.0
broadcast 192.168.29.3
Usable Ip address 192.168.29.2 (The gateway will be 192.168.29.1)

I know i can use a command like ip address get network to get the network ip for instance.
How can i get the Usable ip?(192.168.29.2) in this case from the ip addresses?
I want to use this in a script,but i cant find a command that will return me the usable ips?

Any idea how i can achieve this?

Thanks

Well 'ip address print' is not good enough ?
[admin@MikroTik] ip address> print
Flags: X - disabled, I - invalid, D - dynamic

ADDRESS NETWORK BROADCAST INTERFACE

2 ;;; hotspot network
10.5.50.1/24 10.5.50.0 10.5.50.255 ether5

I'm sure that it is very clear that all the addresses between 10.5.50.0 to 10.5.50.254 might be configured on RouterOS.
However it is not able to specify all usable IP addresses from this subnet, 'ip arp print' show information about current used IP address on the network (however client can switch off PC and ARP entry will be available until timeout).

Yeah,it is clear looking at it,but i was houping for some sort of way to tell my script all these ips,so that it could add rules accordingly.But it’s ok,i sort of have a work around currently using the | operator.

Another question,How can i use &&(and) in find commands?

Say i want to combine /ip address find interface=ether1 and /ip address find disabled=no (I want to find all enabled ips on ether1)
Trying

/ip address find(interface=ether1 && disabled=no) does not work

How can i find all enabled ip’s on intercae ether1?

Thanks

on 2.9 it is not possible with one command, but on v3.0 you can do it like this:

/ip address find where=( interface=ether1 && disabled=no )

There is workaround for v2.9 also.
Run find command with one parameter, after that check from values that were found earlier against other param:

:local lfound [ /ip address find interface=ether1 ];

:for i=0 to=[:len $lFound] do={
    :if ( [/ip address [:pick $lFound $i] disabled ] = no ) do={
        # here you will have ip addresses with interface=ether1 and disabled=no
    }
}

Hi,

Thanks for the reply.That workaround seems to work.

also,what about

[/ip address find interface=ether1 disabled=no]         .

Testing suggests this works.Maybe i’m going crazy and i’m starting to see stuff.

[/ip address find interface=ether1 disabled=no]         .

Yes, that is working too. So actually you don’t need that workaround in this case. But anyway it could help in some other situations :slight_smile:

Another quick question.

How can i find all ips inside a certain range?

Say i have a 172.16.0.0/16 and a 192.169.0.0/16 on a certain interface and i only want to list the ips in the 192 range.
something like

ip /address find [interface=interface src-address=????]

The ??? part must give me all ips in the 192.169.0.0/16 range on the interface.

(I don’t have a 192.169.0.0/16 ip address,I have a lot of /30,/29 etc,but all of them is inside the 192.168.0.0/16 range,i want to list al these ips,i.e 192.169.1/32,192.169.5/32,etc)

Thanks

no it wont, you must check by yourself which address is in 192 range.