Community discussions

MikroTik App
 
alt21
just joined
Topic Author
Posts: 5
Joined: Mon Jun 29, 2009 4:12 am

[Help] Script to add all static ether IP's to address list

Sat Oct 29, 2011 1:01 pm

I'm trying to add all non dynamic IP's assigned to a RouterBOARD's ether interfaces to an address list.
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: [Help] Script to add all static ether IP's to address li

Sat Oct 29, 2011 1:12 pm

What do you mean by "non dynamic" ? do you mean Static ?
Static IP will add to Router interfaces by admin (who log on to Router)
 
alt21
just joined
Topic Author
Posts: 5
Joined: Mon Jun 29, 2009 4:12 am

Re: [Help] Script to add all static ether IP's to address li

Sat Oct 29, 2011 1:41 pm

What do you mean by "non dynamic" ? do you mean Static ?
Static IP will add to Router interfaces by admin (who log on to Router)
Jip I want to add all the static IP's to a list using a script, I could do this manually but we have a couple of RB's in the field and I would like to automate it so I can just add one script that would then find and add all the IP's to an address list

As an example on my RB at home I have.

Address - Interface
172.23.100.65/28 - bridge-network
192.168.57.1/30 - ether2-ipcop
10.10.10.102/30 - eoip-bandit

So the script should find those 3 ranges and add them to an address list which I can then use in a mangle rule.
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: [Help] Script to add all static ether IP's to address li

Sat Oct 29, 2011 1:53 pm

I use this script to find dynamic IP. with this code I get my PPPoE IP and send it via Mail

Note : it can use when there is just one Dynamic IP.
{
local x;
set x [/ip address get [find dynamic] address];
}
but for Static. . . Hmmmmmm?!!

Let me think
 
alt21
just joined
Topic Author
Posts: 5
Joined: Mon Jun 29, 2009 4:12 am

Re: [Help] Script to add all static ether IP's to address li

Mon Oct 31, 2011 1:59 am

Thanks for the help sadeghrafie, this works for me adding the static IP's to an address list.
{
local x;
set x [/ip address find dynamic=no ];
:foreach i in=$x do={
/ip firewall address-list add list=static-ips address=[/ip address get $i address ];
}}
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: [Help] Script to add all static ether IP's to address li

Mon Oct 31, 2011 8:31 am

Good job :D
But, which version of ROS do you use?
 
alt21
just joined
Topic Author
Posts: 5
Joined: Mon Jun 29, 2009 4:12 am

Re: [Help] Script to add all static ether IP's to address li

Mon Oct 31, 2011 10:47 am

Good job :D
But, which version of ROS do you use?
v5.2 - v5.7
 
alt21
just joined
Topic Author
Posts: 5
Joined: Mon Jun 29, 2009 4:12 am

Re: [Help] Script to add all static ether IP's to address li

Mon Oct 31, 2011 1:18 pm

I need to now figure out how to get the script to check if the IP's are already in the address list or not, at the moment it just adds a copy of the same address in the list every time it runs.
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: [Help] Script to add all static ether IP's to address li

Mon Oct 31, 2011 9:21 pm

This code should work but .......
{

:local x;
:local y;
:local z;

:set x [/ip address find dynamic=no ];

:foreach i in=$x do={

:set z [/ip address get $i address ];

:foreach j in=[/ip firewall address-list find] do={

:set y [/ip firewall address-list get number=$j address];

:if (z!=y) do={

/ip firewall address-list add list=static-ips address=z;

}
}
}
}
the result is
interrupted
           value of address expects range of ip addresses
it goes wrong with this >>>> "/ip firewall address-list add list=static-ips address=z;"

Now we should do something that remove "/29" or ... I mean Subnet

Neeeeeeeeeeeeeeeed Heeeeeeeeeeeeeeeeeeeeelp :(
 
sonoracomm
just joined
Posts: 7
Joined: Mon Dec 03, 2012 12:38 am

Re: [Help] Script to add all static ether IP's to address li

Tue Dec 04, 2012 1:56 am

Maybe needs a '$' in front of the 'z'?

Just guessin'

G
 
iRZ0mbie
just joined
Posts: 4
Joined: Sat Nov 07, 2020 3:39 am

Re: [Help] Script to add all static ether IP's to address list

Thu Dec 17, 2020 3:20 am

!dynamic = static

Who is online

Users browsing this forum: No registered users and 35 guests