Code: Select all
:local command "/ip/firewall/address-list/add"
Code: Select all
:local command "/ipv6/firewall/address-list/add"
Code: Select all
$command $args
:local command "/ip/firewall/address-list/add"
:local command "/ipv6/firewall/address-list/add"
$command $args
:global fn do={
:if ($v = 4) do={
/ip/firewall/address-list/add address=$addr list=$list
} else={
/ipv6/firewall/address-list/add address=$addr list=$list
}
}
$fn v=4 addr=1.2.34 list=foo
$fn v=6 addr=1::2 list=foo
:global addIP do={
:local addList $1
:local addIP $2
:local addType 0
:if ($2~"((25[0-5]|(2[0-4]|[01]?[0-9]?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]?[0-9]?)[0-9])(\\/(3[0-2]|[0-2]?[0-9])){0,1}") do={:set addType 4}
:if ([:typeof [:toip6 $2]] = "ip6") do={:set addType 6}
# this do not work on RouterOS because a bug
#:if ([:typeof [:toip6 $2]] = "ip6-prefix") do={:set addType 6}
:local ftest [:find $2 "/" -1]
:local ltest [:len $2]
:if ($ftest > 0) do={
:local testip [:pick $2 0 $ftest]
:local testmk [:pick $2 $ftest $ltest]
:if ( ([:typeof [:toip6 $testip]] = "ip6") and ($testmk~"^\\/(12[0-8]|(1[0-1]|0?[0-9]?)[0-9])\$") ) do={:set addType 6}
}
:if ($addType = 4) do={
/ip firewall address-list add list=$addList address=$addIP
}
:if ($addType = 6) do={
/ipv6 firewall address-list add list=$addList address=$addIP
}
}
:global addIP do={
:local addList $1
:local addIP $2
:local addType $3
:if ($addType = 4) do={
/ip firewall address-list add list=$addList address=$addIP
}
:if ($addType = 6) do={
/ipv6 firewall address-list add list=$addList address=$addIP
}
}
$addIP "my list" 1.2.3.4 4
$addIP "my list" 1.2.3.0/24 4
$addIP "myipv6 list" 1:2:3:4:: 6
$addIP "myipv6 list" 1:2:3:4::/64 6