Community discussions

MikroTik App
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Script doesn't work ok. Please help me solve problem

Sat Sep 28, 2013 2:34 pm

Welcome,
my script:

ros code

:local ipa;
:local ip;
:foreach ip in=[/ip firewall address-list find] do={
    :put [/ppp active find address=[get $ip address]];
}

ros code

[admin@gw-13-02] /ip firewall> address-list print 
Flags: X - disabled, D - dynamic 
 #   LIST                                         ADDRESS                        
 0 D nat-188.116.15.57                            192.168.100.254

ros code

[admin@gw-13-02] /ppp active> print                  
Flags: R - radius 
 #   NAME         SERVICE CALLER-ID         ADDRESS         UPTIME   ENCODING    
 0   5555         sstp    xxxxxxxxxxxx     192.168.100.254   49m44s
The result of this script is:

ros code

/system script> run test01


[admin@
Why doesn't this script return IP, only blank line?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Script doesn't work ok. Please help me solve problem

Mon Sep 30, 2013 2:15 am

If I run this:

ros code

:foreach ip in=[/ip firewall address-list find] do={
    :put [/ppp active find address=[get $ip address]];
}
It returns the error:
interrupted
           invalid value for argument address
Whereas if I save the address as a variable first, then it works.

ros code

:foreach ip in=[/ip firewall address-list find] do={
  :local add [get $ip address]
  :put [/ppp active find address=$add];
}
Dunno why...
 
Ixti
just joined
Posts: 5
Joined: Wed Jun 18, 2008 2:23 am

Re: Script doesn't work ok. Please help me solve problem

Mon Sep 30, 2013 5:11 am

The IP address as stored in the variable also includes the CIDR notation. Try using a small code section to snip it (and thank Boretto):
:local largo [:len $yourIPvariablenamehere];
:local largo [:put ($largo-3)];
:local nomask [:pick $yourIPvariablenamehere 0 $largo];
## replace "local" below with "global" if your IP variable is meant to be global
:local yourIPvariablenamehere $nomask;
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Re: Script doesn't work ok. Please help me solve problem

Mon Sep 30, 2013 7:51 am

Thank you.

Who is online

Users browsing this forum: No registered users and 14 guests