Community discussions

MUM Europe 2020
 
alphalt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Address list from file

Fri May 07, 2010 2:43 pm

Hello,

Lets say I have 500-1000 IP addresses of computers which I want to ban. This list is not generated dynamically. So how to enter it to router ? Is it possible to take it from file, make some list and use in firewall rules ?
Regards,
alpha
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5950
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Address list from file

Fri May 07, 2010 4:57 pm

You can use built in scripting language to read content of the file, parse IP addresses and add them to firewall address list.
 
fewi
Forum Guru
Forum Guru
Posts: 7734
Joined: Tue Aug 11, 2009 3:19 am

Re: Address list from file

Fri May 07, 2010 5:26 pm

Be aware that in the current scripting language the only way to get file content is to read all of it into a variable at once. Variables are currently limited to 4096 bytes at most. Assuming that on average the decimal representation of an octet will take 2 characters, each IP address would be (2 * 4) + 3 + 1 = 12 bytes (4 octets of 2 characters each, 3 dots and a carriage return), so that would give you 341 IP addresses per file. You'll like have to split your list over several files.

If you search the forums, there's many posts in the scripting section that deal with reading in lists from files and processing them. You can probably adjust one of them together with the manual section on scripting you can find on the wiki.
 
User avatar
martini
Member Candidate
Member Candidate
Posts: 296
Joined: Tue Dec 21, 2004 12:13 am

Re: Address list from file

Fri May 07, 2010 5:44 pm

create text file which content string like this

/ip firewall address-list add name="list name" address=x.x.x.a/y
/ip firewall address-list add name="list name" address=x.x.x.b/y
/ip firewall address-list add name="list name" address=x.x.x.c/y
.........
..........
...........

And copy content of this file to mikrotik console, better ise ssh cinsole, not winbox
 
alphalt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Address list from file

Sat May 08, 2010 2:38 pm

Hello,

Thanks for advices, but one more question. How much addresses can hold one address list ? Is there any limit ?
Regards,
alpha
 
User avatar
martini
Member Candidate
Member Candidate
Posts: 296
Joined: Tue Dec 21, 2004 12:13 am

Re: Address list from file

Sat May 08, 2010 8:47 pm

my current address-list count 6879 ip subnet.
 
pturkey
newbie
Posts: 40
Joined: Wed Aug 19, 2009 7:30 pm

Re: Address list from file

Sat May 08, 2010 9:09 pm

Open a new spread sheet.
Put the ip addresses in column B.
Fill column A with /ip firewall address-list add name="list name" address=
Highlight and copy both columns.
Paste it in notepad, then you will need to replace the tabs with a single space.
At that point you should be able to past the results into the terminal.
 
alphalt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Address list from file

Sat May 08, 2010 9:39 pm

Thank you all for advices ! I've got some very good ideas on IP address list management.
Regards,
alpha
 
pturkey
newbie
Posts: 40
Joined: Wed Aug 19, 2009 7:30 pm

Re: Address list from file

Sat May 08, 2010 9:40 pm

This will work better.

Open a new spread sheet.
Put the ip addresses in column B.
Fill column A with "address-list add list=banned address=" no quotes.
Highlight and copy both columns.
Paste it in notepad.
Put /ip firewall at the top of the page.
Remove the tabs between address= and the IP address.
Highlight the tab copy it hit "ctrl H" and paste the tab in the "Find what" field then click the "Replace All".

At that point you should be able to copy and past the results into the terminal.

Who is online

Users browsing this forum: No registered users and 96 guests