Hello!
I’m making a script in bash on a linux box to list all CPE’s on an AP.
When i:
/ip neigh pr
I get all the info mixed, but i need to get Address and Identity but only of the ones that identity starts with CPE-
I tried everything but just cant make it work.
My way around will be to print terse and then awk it on the linux box.. but i wan to learn how to do it on the mt box.
is what you need to filter to only those with identies starting with “CPE-”. And if you want to output them in a custom fashion, you can use the “as-value” argument.
If you’re typing directly into terminal, you need to surround the thing with “{” and “}”, so that it is treated as a single unit. The alternative is to enter it in a script at “/system script”.
Nice discussion ,
I want to display only the identity of the device , i do many tries to get the result but No success …
/ip neighbor print where interface=bridge1 address~"^192.168"
i did a script to detect the rogue dhcp server and it must show the damaged devices identity .. here is the code :
# Count the number of devices who took rouge dhcp ip address
:local loop [:len [/ip neighbor find where interface=bridge1 address~"^192.168"]];
# Discover the identity of the devices who took rouge dhcp ip address <<>> Here is my issue !!
:local id [/ip neighbor find where interface=bridge1 address~"^192.168"]
# Show the number of the devices if found
:if ($loop>0) do={:log warning "$loop"
:delay 2s;
#Show The identity of the Devices if found <<>> Here is my issue !!
:log warning "$id"
}
# If there is no Rouge DHCP Server damages do log : No Loop <<>> Here is another issue !! .. this logs with the twice situations !!!
:else do [:log warning "No Loop";]
Hello, I think this might work for you, just replace your script with this. You can change the $interfaceParam and $addressParam to anything you like and it should output the correct identity. Feel free to ask any questions if something doesn’t work for you.
# DEFINE YOUR SEARCH PARAMETERS
:local interfaceParam "bridge1";
:local addressParam "^192.168";
# INITIALIZE VALUES
:local loop [:len [/ip neighbor find where interface=$interfaceParam address~$addressParam]];
:local id [/ip neighbor find where interface=$interfaceParam address~$addressParam]
:local rogueIdentity;
# OUTPUT THE NUMBER OF ROGUE DEVICES DETECTED
:if ($loop>0) do={:log warning "There are $loop rogue devices"} else={ :log warning "No rogue devices detected"};
# GET IDENTITIES OF ROGUE DEVICES
:foreach var in=$id do={
:set $rogueIdentity [/ip neighbor get [/ip neighbor find where .id=$var] identity];
:log warning "Rogue device $rogueIdentity detected";
#:put $rogueIdentity;
}
Hello, I think this might work for you, just replace your script with this. You can change the $interfaceParam and $addressParam to anything you like and it should output the correct identity. Feel free to ask any questions if something doesn't work for you.
CODE: SELECT ALL
:local loop [:len [/ip neighbor find where interface=$interfaceParam address~$addressParam]];
:local id [/ip neighbor find where interface=$interfaceParam address~$addressParam]
:local rogueIdentity;
OUTPUT THE NUMBER OF ROGUE DEVICES DETECTED
:if ($loop>0) do={:log warning "There are $loop rogue devices"} else={ :log warning "No rogue devices detected"};
>
Thank you so much , It's works as expected :smiley:
You are really a genius , And there is an Arabian saying : teach me fishing better than fish me a fish :slight_smile:
Where can I find the basic rules for learning scripting ? :confused: :confused:
Best Regards my hero !
I suggest starting here https://wiki.mikrotik.com/wiki/Manual:Scripting , all you have to do is just take one router and try to write some basic things, whatever comes to mind, for example: Periodically check routers CPU temperature and output it to console or log. I suggest learning all about {find} and {get} commands in ROS, they are extremely valuable and will definitely be part of most scripts.