Created
February 12, 2025 15:24
-
-
Save elico/1df45406e47aa26cfd2a882bb3dbc940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
:local snmpAddressesString ""; | |
:local snmpAddressesComparisonString ""; | |
:local addressLists {"LIST1"; "LIST2"} | |
:local community "public"; | |
:local currentSnmpAddresses [/snmp/community/get [find where name=$community] addresses]; | |
:foreach addressListName in=$addressLists do={ | |
foreach i in=[/ip/firewall/address-list/find where list="$addressListName"] do={ | |
:local ipAddress [/ip/firewall/address-list/get number=$i address]; | |
:if ( $ipAddress~"^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\$" ) do={ | |
:if ([:len [$snmpAddressesString]] = 0) do={ | |
:set snmpAddressesString ("$ipAddress". "/32"); | |
:set snmpAddressesComparisonString ("$ipAddress". "/32"); | |
} else={ | |
:set snmpAddressesString ($snmpAddressesString . "," . "$ipAddress". "/32"); | |
:set snmpAddressesComparisonString ($snmpAddressesComparisonString . ";" . "$ipAddress". "/32"); | |
} | |
} | |
} | |
} | |
:if ($currentSnmpAddresses != $snmpAddressesComparisonString) do={ | |
/snmp/community/set [find where name=$community] address=$snmpAddressesString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment