Cyber Security
6 min read178 words

Building a High-Performance Windows DNS Switcher with Flask & Netsh Socket Benchmarks

An engineering retrospective on building Public_DNS_Switcher: Interfacing with Windows TCP/IP networking, automating adapter DNS overrides, and live RTT latency pings.

Om Prakash Behera
Om Prakash BeheraCSE Student at GCEK Kalahandi | Full-Stack & AI Engineer

The Motivation: Privacy & Speed

Internet Service Provider (ISP) default DNS servers frequently log browsing queries, inject tracking headers, and resolve hostnames slowly. In Public_DNS_Switcher, I built a desktop web tool to safely switch network adapters between vetted encrypted/privacy providers (Cloudflare 1.1.1.1, Google 8.8.8.8, AdGuard, Quad9 9.9.9.9).

Direct Windows Network Stack Configuration

Instead of clunky third-party binaries, the tool orchestrates native Windows network configuration commands via Python:

pythonCode Snippet
import subprocess
import time
import socket

def set_adapter_dns(adapter_name, primary_ip, secondary_ip=None):
    # Set primary DNS server
    cmd_primary = [
        "netsh", "interface", "ip", "set", "dns",
        f"name={adapter_name}", "static", primary_ip, "primary"
    ]
    subprocess.run(cmd_primary, check=True, creationflags=subprocess.CREATE_NO_WINDOW)
    
    # Set secondary backup DNS server
    if secondary_ip:
        cmd_sec = [
            "netsh", "interface", "ip", "add", "dns",
            f"name={adapter_name}", secondary_ip, "index=2"
        ]
        subprocess.run(cmd_sec, check=True, creationflags=subprocess.CREATE_NO_WINDOW)

Live Latency Benchmarking

Before committing a DNS change, the application executes rapid ICMP / TCP socket pings against all candidate resolvers, displaying live round-trip milliseconds so users always choose the fastest path for online gaming, coding, and privacy.

Related Topics:#Public_DNS_Switcher#Python#Flask#Cyber Security#Windows API