Skip to content

Instantly share code, notes, and snippets.

@ChrisG661
Last active April 13, 2023 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ChrisG661/1549e732e7112d5e2d35598dd17bf4cd to your computer and use it in GitHub Desktop.
Save ChrisG661/1549e732e7112d5e2d35598dd17bf4cd to your computer and use it in GitHub Desktop.
MikroTik Address List Updater
## Generic IP address list input
## Based on a script written by Sam Norris, ChangeIP.com 2008
## Edited by ChrisG661, 2021
## Permissions: ftp, read, write, policy, test
# Check if file is not empty
:if ([/file get [/file find name=$filename] size] > 0) do={
# Remove existing addresses from the current address list
# Disabled as script will use same list for different sourcefiles
#/ip firewall address-list remove [/ip firewall address-list find list=$listname]
# Get file contents
:local content [/file get [/file find name=$filename] contents];
:local contentLen [:len $content];
:local lineEnd 0;
:local line "";
:local lastEnd 0;
:do {
# Seek newline
:set lineEnd [:find $content "\n" $lastEnd];
# Check for last line
:if ([:len $lineEnd] = 0) do={
:set lineEnd $contentLen;
}
# Select line
:set line [:pick $content $lastEnd $lineEnd];
# Set start for next line
:set lastEnd ($lineEnd + 1);
#If the line is not a comment, add to list
:if ([:pick $line 0 1] != "#") do={
:local entry [:pick $line 0 $lineEnd];
:if ( [:len $entry ] > 0 ) do={
:do {/ip firewall address-list add list=$listname address=$entry;
} on-error={:put "IP range duplicate, skipping"};
}
}
} while=($lineEnd < $contentLen)
}
:log info "Added $filename to address list $listname"
@ChrisG661
Copy link
Author

ChrisG661 commented Mar 26, 2021

Permissions: ftp, read, write, policy, test
Use as a function in ROS with :global updateList [:parse [/system script get UpdateAddressList source]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment