Skip to content

eugenescodes/adblock2mikrotik_rust

Repository files navigation

adblock2mikrotik_rust

Convert ad-blocking filter lists to MikroTik RouterOS DNS adlist format.

Note

This is a Rust rewrite of adblock2mikrotik

Tip

Ready-to-use URL for RouterOS: https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik_rust/refs/heads/main/hosts.txt

Overview

Transforms popular ad-blocking filter lists (Hagezi) into a compact format compatible with the MikroTik RouterOS 7.15+ DNS adlist feature. Optimized for memory-constrained low-resource devices like the RB951Ui-2nD hAP (which has 16 MB storage).

Sources

List Description
Hagezi Multi PRO mini General ad/tracker blocking
Hagezi TIF mini Threat intelligence feeds
Hagezi Gambling mini Gambling sites

Features

  • Converts ||example.com^ rules to MikroTik DNS adlist format (0.0.0.0 example.com)
  • Deduplicates entries across all sources
  • Validates domains against RFC label rules (rejects double-dots, leading/trailing hyphens)
  • Pre-filters comments and empty lines for efficiency
  • Compatible with RouterOS 7.15+

Usage

Option 1 — Cargo (recommended)

# Install Rust if not already installed
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Clone and run
git clone https://github.com/eugenescodes/adblock2mikrotik_rust
cd adblock2mikrotik_rust
cargo run --release

After running, hosts.txt is created in the current directory.

Option 2 — Docker

docker build -t adblock2mikrotik_rust .

Important

If hosts.txt does not exist in your current directory, Docker might create it as a directory. Create the file first:

touch hosts.txt
# Linux / macOS
docker run --rm --user $(id -u):$(id -g) -v "$(pwd)":/output adblock2mikrotik_rust

# Windows (PowerShell)
docker run --rm -v "${PWD}:/output" adblock2mikrotik_rust

Note

The -v flag mounts your current directory into the container at /output. The binary writes hosts.txt to /output, so the file appears directly in your current directory on the host — no manual copying needed.

On Linux, --user $(id -u):$(id -g) ensures the output file is owned by your current user. Not required on macOS or Windows (Docker Desktop handles this automatically).

MikroTik RouterOS Integration

Add adlist via URL

/ip/dns/adlist add url=https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik_rust/refs/heads/main/hosts.txt ssl-verify=no

Optional: enable SSL verification

If you want to use ssl-verify=yes, you can download and import CA certificates using the following commands:

/tool fetch url=https://curl.se/ca/cacert.pem
/certificate import file-name=cacert.pem passphrase=""
/ip/dns/adlist add url=https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik_rust/refs/heads/main/hosts.txt ssl-verify=yes

Add adlist from local file

/ip/dns/adlist add file=hosts.txt

See also the official MikroTik documentation:

Configuration

By default, the script uses three pre-configured Hagezi filter lists. You can customize which sources are used by creating a config.toml file:

Customize sources

  1. Copy the example configuration:
cp config.toml.example config.toml
  1. Edit config.toml to add or remove sources:
[sources]
urls = [
    "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.mini.txt",
    "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/tif.mini.txt",
    "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/gambling.mini.txt",
]
  1. Run the converter:
cargo run --release

The script will automatically load sources from config.toml. If the file doesn't exist, it falls back to the default sources above.

Finding additional filter lists

You can use any blocklist in AdBlock format (||domain.com^ syntax)

For more Hagezi lists, visit the Hagezi DNS blocklists repository

Development

This project uses Cargo for dependency management and Clippy + rustfmt for linting/formatting.

Prerequisites

Install Rust via rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Lint and format

# format
cargo fmt --all  

# lint
cargo clippy --all-targets --all-features -- -D warnings  

Tests

cargo test --verbose
cargo test --doc

Contributing

  1. Open a GitHub issue to discuss major changes before starting work.
  2. Fork the repo and create a feature branch: git checkout -b feature/your-feature
  3. Make your changes and run tests: cargo test --verbose
  4. Commit with a clear message and push to your fork.
  5. Open a Pull Request targeting main with a description of what and why.

License

GNU GPL v3.0

Acknowledgments

  • Hagezi for maintaining comprehensive filter lists
  • MikroTik for the DNS adlist feature in RouterOS 7.15+

This tool is not affiliated with MikroTik.

About

Convert AdBlock filter lists to MikroTik RouterOS DNS adlist format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors