Skip to content

Instantly share code, notes, and snippets.

@elico
Created February 12, 2025 15:24
Show Gist options
  • Save elico/1df45406e47aa26cfd2a882bb3dbc940 to your computer and use it in GitHub Desktop.
Save elico/1df45406e47aa26cfd2a882bb3dbc940 to your computer and use it in GitHub Desktop.
{
: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