Windows Network Diagnostics and Reset with Python

A Windows network repair utility written in Python that automates the standard Windows network troubleshooting commands — DHCP release/renew, DNS flush, Winsock and TCP/IP stack reset, proxy reset, adapter restart, and connectivity tests — with a progress bar and colour-coded results.

Python projects · Windows networking

⚠️ This script changes system network settings. Resetting the TCP/IP stack and Winsock catalog can remove static IP addresses, custom DNS servers, and some VPN or network-filter configurations, and restarting adapters disconnects you briefly. Note any custom settings before running it.

Start here

Before running: this Windows script changes network settings and restarts adapters. Read the limitations and prepare for a dropped connection.

Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in FixNetwork/Console_Code/. Install any third-party packages in an isolated Python environment.

Overview

This script automates a series of common network troubleshooting steps — releasing DHCP leases, flushing caches, resetting the TCP/IP and Winsock stacks, restarting the WLAN service, and running connectivity tests — all with a progress bar and color-coded output. It must be run as Administrator.

Features

  • Administrator privilege check before execution
  • Progress bar via tqdm showing step name and completion
  • Color-coded output (green for success, red for failure) via colorama
  • Runs 22 ordered network repair steps:
Category Steps
Diagnostics (before fix) Show IP config, routing table, WinHTTP proxy
DHCP + DNS Release lease, flush DNS, register DNS, renew lease
Cache resets Clear ARP cache, reset NetBIOS cache and names
Proxy & SSL Reset WinHTTP proxy, clear SSL state
Service restart Restart WLAN service
Core resets Reset TCP/IP stack, repair Winsock catalog
Optional resets Reset IPv4 and IPv6 stacks
Adapter restart Disable and re-enable active network adapters
Connectivity tests Ping localhost, gateway, Google DNS (8.8.8.8), DNS lookup

Prerequisites and installation

colorama
tqdm

Install dependencies:

python -m pip install colorama tqdm

Usage

From the Console_Code folder, in a terminal or PowerShell window opened as Administrator:

python network_repair.py

If not run as Administrator, the script will print an error and exit immediately.

After the routine completes, a reboot is recommended for maximum stability.

Architecture

FixNetwork/
└── Console_Code/
    └── network_repair.py    # Main script

Troubleshooting and limitations

  • All commands use subprocess.run() with shell=True. Each step’s output is shown only if the step fails.
  • This tool is Windows-only. It relies on netsh, ipconfig, arp, nbtstat, ping, nslookup, and PowerShell cmdlets.
  • Personal files and installed programs are not touched, but network configuration is: the TCP/IP, IPv4/IPv6, and Winsock resets rewrite network settings (a restart is needed for them to take full effect), DHCP leases are released and renewed, and active adapters are disabled, then the enable command targets all adapters, including ones that were previously disabled.
  • The “Clear SSL state” step runs RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8, which deletes temporary Internet files in the Windows Internet Options cache.

The IPv4/IPv6 steps labelled optional in the source still run on every invocation; there is no selection prompt or dry run. Failed commands print diagnostics, but their return values do not stop the routine or suppress its final Finished message. That message does not prove the network was repaired. The non-administrator path returns without setting a failure exit code.


Read all Python Projects and Code Examples guides online · Project overview · All developer projects