Community discussions

MikroTik App
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Topic Author
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

how to get only ip from queue simple from script

Fri May 09, 2014 7:59 am

Hi.
I am working in a script to get only the ip address from queue simple, but I have a bit problem

the script what I am trying for get only ip address without the netmask is

ros code

foreach i in=[queue simple find ] do={
	local tmp [/queue simple get value-name=target $i]
local ip [pick $tmp 0 [:find $tmp "/"]]
 put $ip}
192.168.88.2/32
192.168.88.3/32
I need only this output

192.168.88.2
192.168.88.3

if I execute this command, is working:

ros code

local tmp 192.168.88.2/32; put [pick $tmp 0 [:find $tmp "/"]]
192.168.88.2


I am wrong but where?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how to get only ip from queue simple from script

Sat May 10, 2014 5:05 pm

I suggest you to read all my post with script... :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how to get only ip from queue simple from script

Sat May 10, 2014 5:11 pm

:local fullIP value="123.45.67.89/10";
:local onlyIP value=[:pick $fullIP -1 [:find $fullIP "/"]];
DO NOT PLACE SPACE BETWEEN "-" AND "1" on "-1"

And if you want, remember Karma....


EDIT: this is one example, remember to pass STRING variable inside fullIP, not a IP variable....
Last edited by rextended on Sat May 10, 2014 11:57 pm, edited 1 time in total.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Topic Author
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: how to get only ip from queue simple from script

Sat May 10, 2014 6:46 pm

not work...

ros code

foreach o in=[queue simple find] do={
{... :local fullIP value=[queue simple get value-name=target $o]
{... :local onlyIP value=[:pick $fullIP -1 ([:len $fullIP] - 3)];
{... put $onlyIP                                                 
{... }           


[admin@MikroTik] >

ros code

foreach o in=[queue simple find] do={
{... :local fullIP value=[queue simple get value-name=target $o]
{... put $fullIP                                                
{... }           
192.168.88.2/32
192.168.88.3/32
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how to get only ip from queue simple from script

Sat May 10, 2014 11:52 pm

Try to use correct syntax in your script, this solve the problems...
:foreach o in=[/queue simple find] do={
 :local fullIP value=[:tostr [/queue simple get $o value-name=target]];
 :local onlyIP value=[:pick $fullIP -1 [:find $fullIP "/"]];
 :put $onlyIP;
};
And remember: not all the time the target are one IP, can be also pppoe-client or another interface...
 
rzirzi
Member
Member
Posts: 393
Joined: Mon Oct 09, 2006 2:33 pm

Re: how to get only ip from queue simple from script

Fri Oct 05, 2018 4:35 pm

rextended - how to change Your script for:
1) change all SimpleQueues from 192.168.xx.1 to 192.168.zz.1 (all queues from 100 to 200)
2) change all PPPoE secrets addresses like SimpleQueues
Tahk You.

Who is online

Users browsing this forum: No registered users and 41 guests