That part works just fine.
I want to also create a file that can be imported to other MT routers to replicate the list in other routers.
I build the entire command list in a variable called "exportcmds"
I can even send it to the router logs as its being built and all looks good.
However the final command in this script to write that content to a file simply does not work.
The content list ends up being about 1950 "add address <IP address> list=BotNetCCandDrop timeout=1d; commands
I'm wondering if that is just too big to be written to a file.
The resulting file would only be about 170K or so. Not that large.
But is that too large for a /file set command?
Code: Select all
#This script will take the routes added via BGP peering from Spamhaus and add to fw address list "BotNetCCandDrop" so that inbound and outbound traffic can be blocked by fw RAW rules.
{
:local RawIP;
:local i;
:local exportcmds;
:local filename "BotNetAndDrop"
#Initialize file. Creates and clears file. Note that this put .txt on the end of the filename.
/file print file=$filename;
delay 2s;
/file set "$filename.txt" contents="";
:set exportcmds ($exportcmds . "#Import script to add BoNetCCandDROP list to router\r\n /ip firewall address-list\r\n")
#/file set "$filename.txt" contents=$exportcmds;
#initilize output file
#
#/file set $filename contents=$exportcmds;
#:set exportcmds [/file get $filename contents];
#remove existing list
/ip firewall address-list remove [/ip firewall address-list find list="BotNetCCandDrop"];
:foreach i in=[/ip route find where bgp-as-path=65190 active ] do={
:set $RawIP [/ip route get $i dst-address];
# :log info "adding IP $RawIP to BotNetCC list";
/ip firewall address-list add address=[/ip route get $i dst-address] list=BotNetCCandDrop timeout=1d;
:set exportcmds ($exportcmds . "add address=$RawIP list=BotNetCCandDROP timeout=1d;\r\n");
# :log info "add address=$RawIP list=BotNetCCandDROP timeout=1d;";
}
#:log info "filename=$filename.txt";
#:log info "file contents=$exportcmds";
/file set "$filename.txt" contents=$exportcmds;
}