## Parse DSHIELD feed and build an address-list.
## Written by Sam Norris, ChangeIP.com 2008
## Any comments or suggestions welcome in the forums.
##
## 06/03/08 - Initial list parsing.
#/tool fetch address=feeds.dshield.org host=feeds.dshield.org mode=http path=block.txt
:if ( [/file get [/file find name=block.txt] size] > 0 ) do={
/ip firewall address-list remove [/ip firewall address-list find list=dshield]
:global content [/file get [/file find name=block.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != "#" ) do={
:if ([:typeof [:toip [:pick $line 0 [:find $line "\t"] ] ] ] != "nil") do={
:local pos1 [:find $line "\t" 0]
:local pos2 [:find $line "\t" $pos1]
:local pos3 [:find $line "\t" $pos2]
:log info ( "DShield Entry: " . [:pick $line 0 $pos1 ] . "/" . [:pick $line ($pos2+1) $pos3 ] )
/ip firewall address-list add list=dshield address=( [:pick $line 0 $pos1 ] . "/" . [:pick $line ($pos2+1) $pos3 ] )
}
}
} while ($lineEnd < $contentLen)
}
[xxx@rancheros-AP] > /ip firewall address-list print from=[/ip firewall address-list find list=dshield]
Flags: X - disabled, D - dynamic
# LIST ADDRESS
0 dshield 125.211.198.0/24
1 dshield 193.164.131.0/24
2 dshield 81.3.247.0/24
3 dshield 81.3.248.0/24
4 dshield 220.128.206.0/24
5 dshield 81.3.244.0/24
6 dshield 81.3.249.0/24
7 dshield 81.192.191.0/24
8 dshield 81.3.243.0/24
9 dshield 81.3.250.0/24
10 dshield 70.21.127.0/24
11 dshield 218.6.8.0/24
12 dshield 202.138.172.0/24
13 dshield 81.3.246.0/24
14 dshield 202.99.254.0/24
15 dshield 202.6.225.0/24
16 dshield 99.129.23.0/24
17 dshield 76.88.8.0/24
18 dshield 60.222.231.0/24
19 dshield 222.187.221.0/24
## Parse DSHIELD & Spamhaus feed and build an address-list.
## Written by Sam Norris, ChangeIP.com 2008
## Any comments or suggestions welcome in the forums.
##
## 06/03/08 - Initial list parsing.
#/tool fetch address=feeds.dshield.org host=feeds.dshield.org mode=http path=block.txt
#/tool fetch address=www.spamhaus.org host=www.spamhaus.org mode=http path=drop/drop.lasso
##
## DSHIELD Drop List
##
:if ( [/file get [/file find name=block.txt] size] > 0 ) do={
/ip firewall address-list remove [/ip firewall address-list find list=dshield]
:global content [/file get [/file find name=block.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != "#" ) do={
:if ([:typeof [:toip [:pick $line 0 [:find $line "\t"] ] ] ] != "nil") do={
:local pos1 [:find $line "\t" 0]
:local pos2 [:find $line "\t" $pos1]
:local pos3 [:find $line "\t" $pos2]
:log info ( "DShield Entry: " . [:pick $line 0 $pos1 ] . "/" . [:pick $line ($pos2+1) $pos3 ] )
/ip firewall address-list add list=dshield address=( [:pick $line 0 $pos1 ] . "/" . [:pick $line ($pos2+1) $pos3 ] )
}
}
} while ($lineEnd < $contentLen)
}
##
## SPAMHAUS.ORG Drop List
##
:if ( [/file get [/file find name=drop.lasso] size] > 0 ) do={
/ip firewall address-list remove [/ip firewall address-list find list=spamhaus.lasso]
:global content [/file get [/file find name=drop.lasso] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != ";" ) do={
:if ([:len [:pick $line 0 [:find $line ";"] ] ] > 0 ) do={
:local pos1 [:find $line ";" 0]
:local entry [:pick $line 0 ($pos1-1) ]
:if ( [:len $entry ] > 0 ) do={
:log info "Lasso Entry: $entry"
/ip firewall address-list add list=spamhaus.lasso address=$entry
}
}
}
} while ($lineEnd < $contentLen)
}
## Generic IP address list input
## Based on a script written by Sam Norris, ChangeIP.com 2008
:if ( [/file get [/file find name=node-unmetered-ips.txt] size] > 0 ) do={
/ip firewall address-list remove [/ip firewall address-list find list=Node-Unmetered]
:global content [/file get [/file find name=node-unmetered-ips.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != "#" ) do={
:local entry [:pick $line 0 ($lineEnd -1) ]
:if ( [:len $entry ] > 0 ) do={
/ip firewall address-list add list=Node-Unmetered address=$entry
}
}
} while ($lineEnd < $contentLen)
}
## QLD PIPE Address List
## Based on a script written by Sam Norris, ChangeIP.com 2008
:if ( [/file get [/file find name=qld.txt] size] > 0 ) do={
/ip firewall address-list remove [/ip firewall address-list find list=qld-pipe]
:global content [/file get [/file find name=qld.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != "#" ) do={
:if ([:len [:pick $line 0 [:find $line ","] ] ] > 0 ) do={
:local pos1 [:find $line "," 0]
:local entry [:pick $line 0 ($pos1) ]
:if ( [:len $entry ] > 0 ) do={
:log info "QLDPIPE: $entry"
/ip firewall address-list add list=qld-pipe address=$entry
}
}
}
} while ($lineEnd < $contentLen)
}
:set linecount [:len [:readline test.txt]]
:set thisline [:readline test.txt 20]
:set nextline [:readline test.txt]
:if ([:writeline test.txt $newline] = [:len $newline]) do={:set writeok true} else={:set writeok false}
#create file
/file print file=test
#write to file
/file set test.txt contents="lalala";
#add another line
/file set test.txt contents=( get test.txt contents ] . "\nlalalala" );
Yes, forgot to mention that.Now the bad news. 4095 bytes max.
:global ipAddr 1.1.1.1
/file print file=test
/file set test.txt contents="lalala $ipAddr "
/file :put [ get test.txt contents ]
[admin@Krusher] > system script run not-working-script
syntax error (line 1 column 9)
[admin@Krusher] >
not work 6.5..## Generic IP address list input
## Based on a script written by Sam Norris, ChangeIP.com 2008
## Edited by Andrew Cox, AccessPlus.com.au 2008
:if ( [/file get [/file find name=ipaddress.txt] size] > 0 ) do={
# Remove exisiting addresses from the current Address list
/ip firewall address-list remove [/ip firewall address-list find list=MY-IP-LIST]
:global content [/file get [/file find name=ipaddress.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
#If the line doesn't start with a hash then process and add to the list
:if ( [:pick $line 0 1] != "#" ) do={
:local entry [:pick $line 0 ($lineEnd -1) ]
:if ( [:len $entry ] > 0 ) do={
/ip firewall address-list add list=MY-IP-LIST address=$entry
}
}
} while ($lineEnd < $contentLen)
}