i have a text file contain a list of domains
i want to import the domains to address-list firewall
please help me to write this script.
thanx.
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
/ip firewall address-list add list=drop_traffic 1.1.1.1
/ip firewall address-list add list=drop_traffic 2.2.2.2
/ip firewall address-list add list=drop_traffic 3.3.3.3
/ip firewall address-list add list=drop_traffic 4.4.4.4
/import name.rsc
/ip firewall address-list {
add list=drop_traffic address=[:resolve vzshuq.com]
add list=drop_traffic address=[:resolve abc.cpm]
add list=drop_traffic address=[:resolve irna.ir]
}
:local domains {"vzshuq.com";
"abc.cpm";
"irna.ir";}
/ip firewall address-list {
:foreach d in=[:toarray $domains] do={
add list=drop_traffic address=[:resolve [:tostr $d]]
}
}
To solve this problem, here is my solution:dont forget that if the :resolve fails the entire script will abort ... hopefully this will be improved in newer RouterOS versions (if it hasnt already? not in any release notes)
:local domains {"vzshuq.com";
"abc.cpm";
"irna.ir";}
:foreach d in=[:toarray $domains] do={
:execute ("/ip firewall address-list add list=drop_traffic address=[:resolve " . [:tostr $d] . "]")
}
Unmodified file:
domain1.tld
domain2.tld
domain3.tld
Edited file:
"domain1.tld";
"domain2.tld";
"domain3.tld";
Normis, he mentions thousands of entries - can routerboard handle it?1. address list CAN'T contain domain names
2. you must use Proxy and Proxy Access List
:local date [/system clock get date]
#download current days domain list
/tool fetch address=www.epicwinrar.com host=www.epicwinrar.com mode=http src-path="conficker/domains.txt"
:log info "Download Complete"
:delay 2
#check to ensure todays file exists before deleting yesterdays list
:log info "Begining Address List Modification"
:if ( [/file get [/file find name="domains.txt"] size] > 0 ) do={
:local content [/file get [/file find name="domains.txt"] contents] ;
:local contentLen [ :len $content ] ;
:local lineEnd 0;
:local line "";
:local lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
#resolve each new line and add to the address list daily-conficker. updated to list domain as comment
:if ( [:pick $line 0 1] != "\n" ) do={
:local entry [:pick $line 0 ($lineEnd ) ]
:if ( [:len $entry ] > 0 ) do={
:local listip [:resolve "$entry"]
:if ($listip != "failure" ) do={
:if ((/ip firewall address-list find list=daily-conficker address=$listip) = "") do={
/ip firewall address-list add list=daily-conficker address=$listip comment=$entry
:log info "$listip"
} else={:log info "duplicate IP $entry"}
}
}
}
} while ($lineEnd < $contentLen)
}
:log info "Address List Modification Complete"
system script run daily-conficker-list
status: finished
I suspect that large client using ROS proxy with thousands of ACL entries, that Normis mentions, is using a PC with much more power and memory.
Edit: http://forum.mikrotik.com/viewtopic.php?f=2&t=38540 here is the thread - looks like rmichael was trying it out, too.