Skip to content
Matheus Amorim

2025

DNS Manager

Command-line utility for Windows that applies or restores DNS on the connected interfaces and turns IPv4 and IPv6 on or off across every adapter, born out of a real need at work.

  • Python
  • CLI
  • Windows
  • PowerShell
  • PyInstaller
  • Networking

Context

I needed to switch quickly between DNS configurations to connect to a Pi-hole running in a VM, used as the operation's DNS filter. Doing that through the Windows interface on every switch is slow and error-prone — especially because it involves IPv4 and IPv6 at the same time, on separate screens.

DNS Manager is the answer: an interactive menu in Python that detects the connected network interfaces, applies the chosen operation in one go and records every step in a log file. It was designed for technicians and support teams that need to change the DNS of several machines quickly, without depending on the Windows settings screens.

Technical decisions

CLI, not a graphical interface. The operation is a configuration switch, not exploration. One command does what the Windows interface does in six clicks spread across three windows — and a command can be scripted later, which a GUI cannot. The menu has eight options: apply a custom DNS, restore automatic DNS (DHCP), enable or disable IPv4 and IPv6, view the log and exit.

Wrap netsh and PowerShell, do not reinvent them. The program runs netsh interface show interface and treats as connected the lines containing "Conectado" or "Connected", so it works on Windows in Portuguese and in English. DNS is applied with netsh interface ip set dns on each connected interface, and restoring uses source=dhcp. IPv4 and IPv6 are turned on and off through the Enable-NetAdapterBinding and Disable-NetAdapterBinding cmdlets, across every adapter — hence the requirement of Windows 8 or later, where those cmdlets exist.

Validate and confirm before changing what is deliberate. Applying a custom DNS and restoring DHCP ask for confirmation, and the IP format is validated before any change. Enabling and disabling IPv4 and IPv6 run immediately.

Administrator required, checked on entry. The check uses IsUserAnAdmin from shell32; without the privilege, the program exits.

Packaging with PyInstaller. The goal was to run on any Windows machine in the operation without depending on the system version or on having Python installed. build.bat cleans build/ and dist/, runs PyInstaller with DNSManager.spec and produces a single-file DNSManager.exe, with a console, its own icon and the .env embedded. To distribute, only the executable is copied.

Tests that never touch the machine. The suite uses unittest from the standard library and mocks the network commands, so it runs without administrator privileges and does not change the tester's configuration.

Result

Tool packaged as an executable, in real use at work. Modular structure — menu, privileges, interfaces, DNS, IPv4, IPv6 and log in separate modules — with a script-automated build and every console message written, with date and time, to the log file.

The limitations are documented in the README, not hidden: there is no per-interface selection, only one primary IPv4 DNS is configured, restoring means forcing DHCP rather than returning to the previous configuration, and disabling IPv4 drops connectivity without asking for confirmation.

Learnings

Automation is born from repeated irritation. The tool exists because the same sequence of clicks happened enough times to be worth an afternoon of code — and that has been my criterion for deciding what to automate ever since.