eworm-de / routeros-scripts

a collection of scripts for MikroTik RouterOS
GNU General Public License v3.0
1.27k stars 286 forks source link

[Feature Request] fw-addr-lists : JSON parsing #79

Closed BadFlo closed 5 days ago

BadFlo commented 2 weeks ago

Hi,

spamhaus.org offers IPv6 blocking list in JSON format only.

I don't think it would require a lot of work to add the functionality.

I'll get on it and try to create a Pull Request.

BadFlo commented 1 week ago

v1 working with Spamhaus IPv4 and IPv6 json files :

https://www.spamhaus.org/drop/drop_v4.json
https://www.spamhaus.org/drop/drop_v6.json

Added this after line 91 (:local Address ...) :

        :if ($Line ~ "^\\{") do={
          :set Address ([ :pick $Line ([ :find $Line "\"cidr\":\"" ]+8) [ :find $Line "\",\"" ] ] . ($List->"cidr"));
        }

Next step is to have a proper JSON section in the script to convert the Lines instead of this hacked :find.

eworm-de commented 1 week ago

Oh well. 😳😕 Actually this is not one JSON document, but one per line. Why do they do that!? Makes it a lot harder to sparse, as we can not deserialize with RouterOS's functionality in one go.

Also... Is this format specified anywhere or is it a proprietary invention by them?

eworm-de commented 1 week ago

Can you give ef2d695c23a8df1efa6096c323583641a8c8182a a try? (The config should look like that in 83dceee6fd89d42216e8edbe8599b02c71151abf.)

See info on branches for an easy way to get the code to your device.

BadFlo commented 1 week ago

@eworm-de, looks perfect. Same result as with my code, but yours is cleaner and may even work better for other files.

But not for ipblocklist_recommended.json from feodotracker.abuse.ch

Right now it's not a great testfile as there is only one entry ...I'll monitor and adapt your code to work with this (better) format too.

Regarding your question about the json format, I didn't find an answer on their website. I'll ask them by mail and keep you posted if I find anything interessting.