de051710e372e1e956ec94629812feeae911309a
AdGuard DNS Rewrite Sync Tool
This script synchronizes DNS rewrite rules between a local YAML configuration and an AdGuard Home instance using its REST API.
Features
- Logs into AdGuard Home via its control API
- Loads desired DNS rewrite entries from a YAML file
- Retrieves current DNS rewrite rules from AdGuard
- Compares current vs. desired state and:
- Adds new entries
- Updates existing ones with changed IPs
- Deletes entries no longer needed
- Merges local and remote rules and writes back to the YAML file
Requirements
- Python 3.7+
requestspyyamlpython-dotenv
Install dependencies:
pip install -r requirements.txt
## Configuration
Create a .env file in the same directory with the following variables:
```env
ADGUARD_URL=http://<adguard-host>:3000
ADGUARD_USER=admin
PASSWORD=yourpassword
YAML_FILE=rewrites.yaml
YAML File Format
The YAML file should contain rewrite entries under the rewrites key:
rewrites:
- domain: "example.org"
answer: "127.0.0.1"
- domain: "another.example.org"
answer: "192.168.1.1"
Usage
Run the script:
python main.py
Description
Languages
Python
100%