I have been trying to create a script to get illegal logins IPs for a NVR email notivfcation to mikrotik to block them automatically. I have code.gs from github getting them (
GitHub response code: 200) but the script in mikrotik is invalid. I am using A.I. to generate the script, as i have no other mean.
I am getting errors like that:
invalid (script window)
on run: executing script import_nvr_blacklist from winbox failed, please check it manually (log file)
failure: Fetch failed with status 404 (/tool/fetch; line 7)
executing script from scheduler (auto-nvr-blacklist) failed, please check it manually
Actual Script:
--- NVR Blacklist Updater ---
:local url "https://raw.githubusercontent.com/burneykh/680ac5379e39be6869733859abe83318/main/nvr_ips.csv"
:local file "nvr_ips.csv"
:put "Starting NVR blacklist update..."
/tool fetch url=$url dst-path=$file mode=https keep-result=yes
:delay 2
:if ([/file find name=$file] = "") do={
:put "Download failed - no file."
:return
}
:local content [/file get $file contents]
:local added 0
:local total 0
:local ip ""
:foreach line in=[:toarray $content] do={
:set ip $line
:if ([:len $ip] = 0) do={ :continue }
:if ([:pick $ip 0] = "#") do={ :continue }
:if ([/ip firewall address-list find where list="nvr_blacklist" and address=$ip] = "") do={
/ip firewall address-list add list="nvr_blacklist" address=$ip comment="Auto NVR Block"
:set added ($added + 1)
:put ("Added " . $ip)
}
:set total ($total + 1)
}
:put ("Processed: " . $total)
:put ("Added: " . $added)
:if ([/ip firewall filter find where chain=input and src-address-list="nvr_blacklist"] = "") do={
/ip firewall filter add chain=input src-address-list="nvr_blacklist" action=drop comment="Block NVR IPs (INPUT)"
:put "Added INPUT rule"
}
:if ([/ip firewall filter find where chain=forward and src-address-list="nvr_blacklist"] = "") do={
/ip firewall filter add chain=forward src-address-list="nvr_blacklist" action=drop comment="Block NVR IPs (FORWARD)"
:put "Added FORWARD rule"
}
/file remove $file
:put "Blacklist update complete."