Ip search by address and enable

Hello there!

I need to find ip addresses where :
The ip address is need to be:
10.100.0.* or 10.100.*.1 and if this statement is true than i need to run something.
my try:

if ([:len [/ip address find where address=10.100.0.* disabled=no]]>0
or
[:len [/ip address find where address=10.100.*.1 disabled=no]]>0) do={};

probably it doesn’t work for me.
So i tried with regex but i don’t know how to use it…

if ([:len [/ip address find where address=10.100.0.“[1]{1,3}” disabled=no]]>0
or
[:len [/ip address find where address=10.100.*.1 disabled=no]]>0) do={};

but unfortunately that’s give me back 0 too so idk what can i do.
So give me a helping hand please :slight_smile:


  1. 0-9 ↩︎

There are several error in your logic.

You search for a range of IP, but you does not tell where the disable command should look.

Also what would you like to happen if it find three IP and 2 are enabled a 1 is disabled?

To use wildcard, you can use:

:put [/ip address find where address~"10.100.0.*"]

To test 1 specific IP, if its found and enabled:

{
/ip address 
:local IPID [find where address~"10.100.21.1"]
:if ([:len $IPID]=0) do={
	:put "ip not found"
} else={
	:local IPStatus [get $IPID disabled]
	:if ([:len $IPID]>0 && $IPStatus=false) do={
		:put "ip found and enabled"
	} else={
		:put "ip found and disabled"
	}
}
}

You can test more IP, but then you need to use a loop.

i want to exchange ospf instence router id from 0.0.0.0 to a 10.100. something address.
But:
i dont want to exchange the address to a severel ways, like if the address is something like this:

addresses with network 10.100.0.0/24
or
address like 10.100.*.1

so i need to unselect these addresses, in different routers so i cant select only one ip and check it, because i don’t know the complete ip

And i think if i try to put an address into a variable and its doesnt exists than the script got an error and break the script

If these ranges only contain one IP this should work,

{
/ip address 
:local IPID [find where address~"10.100.0.*"]
:if ([:len $IPID]=0) do={
	:put "ip not found"
} else={
	:local IPStatus [get $IPID disabled]
	:if ([:len $IPID]>0 && $IPStatus=false) do={
		:put "ip found and enabled"
	} else={
		:put "ip found and disabled"
	}
}
}

But since I do not have any clue about OSPF, I am not sure how to implement this.

probably i can’t circumscribes clearly what i want exactly so :smiley: i end this part of my question and because i don’t want to make another one i write my new question to here.

if this symbol ~ mean the “something like” than what is the it’s not like as
i thinked its will be the !~ but that’s give me back 0 collums.
And i know its again a rly rly bad question, but thats me.. i cant make any good question

~ Does contain some.

http://forum.mikrotik.com/t/filtering-output/148743/1


:if ("abtestcd"~"test") do={
 :put "test found"
} else={
 :put "test not found"
}


:if (!("abtestcd"~"test")) do={
 :put "test not found"
} else={
 :put "test found"
}

sorry, but * = zero or more of previous

10.100.0.* can match (ignoring previous dot) 10.100.0, 10.100.0/, 10.100.0//, … 10.100.0aaaa … 10.100.011111111111111111111111111111111111111 … etc.

Go easy…

See my example:

it do not consider valid IP the IP or ranges with prefix like 10.100.12.15/32 or 10.100.15.0/24

:global testStart 10.100.10.0
:global testEnd 10.100.99.0
:global compare 10.100.55.55

:if ([:typeof $compare] = "ip") do={
  :if ( ([:toip $compare] >= $testStart) && ([:toip $compare] <= $testEnd) ) do={
   :put "IP on range"
  } else={
   :put "IP out of range"
  }
}

@rextended

You are correct. Since it regex it should be like this for 10.100.0.*:

:put [/ip address find where address~"10\\.100\\.0\\.[0-9]+"]

Or even more correct

:put [/ip address find where address~"10\\.100\\.0\\.[0-9]{1,3}"]

And for 10.100.*.1 :

:put [/ip address find where address~"10\\.100\\[0-9]{1,3}\\.1"]

PS In your example I would have used local variable and not global, if the variable are not needed outside the script.

Probably i solved it. Probably i wanted the else statement because if the if statement is true than it’s probably not good for me. But than i used something like this:

if ([:len \\\r\
    \n[/ip address find where address~\"^10\\\\.100\\\\.([1-9]{1,3}|[0-9]{2,3})\\\\.\
    ([02-9]{1,3}|[0-9]{2,})\" disabled=no]]>0) \\\r\
    \ndo={

So i’m sry to steal your time.