Skip to content

hwisnu222/DNS-Auto-Switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DNS Auto Switcher Documentation

πŸ“ Description

A Python script that automatically tests and switches to the fastest available DNS server at regular intervals. Designed for Linux systems using NetworkManager.

πŸ›  Requirements

  • Python 3.x
  • Linux with NetworkManager (nmcli)
  • dig command (from dnsutils package)
  • Root privileges

πŸš€ Installation

# Install dependencies
sudo apt-get install dnsutils network-manager  # Debian/Ubuntu
sudo yum install bind-utils NetworkManager    # RHEL/CentOS

# Make script executable
chmod +x dns_switcher.py

βš™οΈ Configuration

DNS Server List

DNS_SERVERS = {
    "Google": ["8.8.8.8", "8.8.4.4"],
    "Cloudflare": ["1.1.1.1", "1.0.0.1"],
    # ... (17 other providers)
}

Check Interval

CHECK_INTERVAL = 300  # 5 minutes (adjust as needed)

πŸƒβ€β™‚οΈ Usage

sudo ./dns_switcher.py

Press Ctrl+C to stop the script

πŸ”§ Functions

test_dns_speed(servers)

  • Tests response times using dig command
  • Returns: {"Provider": latency_ms, ...}

set_dns(servers)

  • Configures DNS via NetworkManager
  • Returns: True if success, False if failed

main()

  • Main control loop
  • Handles testing, switching, and interval timing

πŸ–₯️ Output Example

==================================================
πŸ•’ Testing for fastest DNS (Interval: 300s)...

πŸ“Š Test Results:
Google: 24.53 ms
Cloudflare: 18.21 ms
Quad9: 32.67 ms

⚑ Fastest DNS changed to: Cloudflare (18.21 ms)
βœ… DNS changed to Cloudflare: 1.1.1.1, 1.0.0.1

πŸ› Troubleshooting

Issue Solution
DNS changes fail Run with sudo
No test results Install dnsutils
Connection errors Check NetworkManager

πŸ“œ License

MIT License - Free for modification and distribution

πŸ’‘ Notes

  • Changes persist until network restart
  • Tested on Ubuntu/Fedora
  • Add providers by editing DNS_SERVERS dictionary

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages