Skip to main content

How to Display the Routing Table in Batch Script

The Routing Table is your computer's map of the network. It defines where packets go when they leave your machine, whether they stay on your local network, go through a specific VPN tunnel, or head out to the internet via the default gateway. When you can't reach a website or another server in your office, the routing table is the first place you should look for errors like hidden routes or incorrect priorities (metrics). A Batch script can use the route print command to display this map, allowing you to audit your network paths in real time.

This guide will explain how to view and filter the Windows routing table.

Method 1: Displaying the Full Routing Table

The simplest way to see everything is to run the route print command. It shows the Interface List, IPv4 routes, and IPv6 routes.

@echo off
setlocal

echo [AUDIT] Displaying Active Routing Table...
echo.

rem --- Display the full table ---
rem --- Pipe through "more" to prevent output from scrolling past the screen ---
route print | more

endlocal
pause

Method 2: Filtering for Specific Networks

In a large network, the routing table can have hundreds of entries. You can use findstr to focus only on the segment you care about. The route print command also accepts a destination filter directly, which is more reliable than piping through findstr because it uses the built-in matching of the route command itself.

Option A: Using the Built-In Filter

@echo off
setlocal

set "Target=192.168.*"

echo [SCAN] Searching for routes matching %Target%...
echo.

rem --- route print accepts a wildcard filter as a direct argument ---
rem --- This shows only routes whose destination matches the pattern ---
route print %Target%

endlocal
pause

Option B: Using findstr for More Flexible Matching

@echo off
setlocal

set "Target=192.168."

echo [SCAN] Searching for routes containing "%Target%"...
echo.

rem --- Print a header for context ---
echo Network Destination Netmask Gateway Interface Metric
echo ---------------------------------------------------------------------------

rem --- Filter the route print output for lines containing the target ---
route print -4 | findstr /c:"%Target%"

rem --- Check if any results were found ---
if %errorlevel% neq 0 (
echo.
echo [INFO] No routes found matching "%Target%".
)

endlocal
pause

Method 3: Displaying IPv4 Routes Only

If you are not using IPv6, the standard output includes a large IPv6 section that adds clutter. The route print command does not have a -4 flag, unlike ping or tracert. Instead, you filter IPv4 routes by passing a wildcard pattern that matches only dotted-decimal addresses.

@echo off
setlocal

echo [NET] Displaying IPv4 routing table...
echo.

rem --- Pass a broad wildcard to match all IPv4 destinations ---
rem --- This excludes the IPv6 section and the Interface List ---
route print -4 *.*

endlocal
pause

An alternative approach that captures the full IPv4 section including headers:

@echo off
setlocal enabledelayedexpansion

echo [NET] IPv4 Routing Table:
echo.

rem --- Use findstr to show only lines that contain dotted-decimal patterns ---
rem --- or the column header line ---
set "Found=0"
for /f "delims=" %%a in ('route print ^| findstr /r /c:"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9]" /c:"Network Destination" /c:"Netmask"') do (
echo %%a
set "Found=1"
)

if "!Found!"=="0" (
echo [INFO] No IPv4 routes found.
)

endlocal
pause

Method 4: Saving a Routing Table Snapshot

When setting up a new VPN or network adapter, saving a baseline copy of your routing table lets you compare "before" and "after" to see exactly what changes the software made.

@echo off
setlocal

rem --- Build a timestamped filename ---
set "Timestamp=%date:~-4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2%"
set "Timestamp=%Timestamp: =0%"
set "OutputFile=%~dp0routing_table_%Timestamp%.txt"

echo [AUDIT] Saving routing table snapshot...

(
echo ============================================
echo Routing Table Snapshot
echo Date: %date% Time: %time%
echo Computer: %COMPUTERNAME%
echo User: %USERNAME%
echo ============================================
echo.
route print
) > "%OutputFile%"

if exist "%OutputFile%" (
echo [SUCCESS] Routing table saved to:
echo %OutputFile%
) else (
echo [ERROR] Failed to save routing table.
)

endlocal
pause

How to Avoid Common Errors

Wrong Way: Using Multiple Wildcards

Because the route print command expects only a single [destination] argument, attempting to filter by passing multiple wildcard parameters separated by spaces will cause a syntax error (such as route: bad argument 2*).

rem *** WRONG - multiple arguments cause a syntax error ***
route print 0.* 1* 2* 3* 4* 5* 6* 7* 8* 9*

Correct Way: Force IPv4 mode using the -4 flag and use a single wildcard (*.*) to match all dotted-decimal IPv4 destinations. This concisely filters out both the Interface List and the IPv6 section.

rem *** GOOD: single wildcard correctly filters IPv4 destinations ***
route print -4 *.*

Wrong Way: Ignoring the Metric Column

If you have two routes to the same network (e.g., Wi-Fi and Ethernet both connected), Windows uses the Metric to decide which path to prefer. A lower number means higher priority.

Correct Way: When troubleshooting, always check the metric. If your Wi-Fi metric is 25 and your Ethernet metric is 10, Windows will prefer Ethernet. If the Ethernet cable is faulty, traffic still routes through it and fails, even though Wi-Fi is working.

Problem: Output Scrolls Past the Screen

The routing table is often longer than your terminal window. Important entries at the top disappear before you can read them.

Solution: Pipe through more for interactive paging, or save to a file for review.

rem --- Interactive paging ---
route print | more

rem --- Save to file ---
route print > "%~dp0routing_table.txt"

Best Practices and Rules

1. Understand the Default Route

The destination 0.0.0.0 with the mask 0.0.0.0 is your Default Gateway route. This is the most important entry in the table, it tells Windows where to send all traffic that doesn't match any more specific route. If this entry is missing or points to the wrong IP, you will have no internet access.

2. Don't Delete System Routes

You will see entries for 127.0.0.0 (loopback), 224.0.0.0 (multicast), and 255.255.255.255 (broadcast). These are essential for internal Windows communication and should never be deleted.

3. Save Baselines Before Changes

Before installing a VPN client, adding a network adapter, or running a configuration script, save your routing table to a file. Comparing the before and after snapshots reveals exactly what was added, removed, or modified.

4. Use setlocal / endlocal

Always wrap scripts in setlocal and endlocal to prevent variables from leaking into the parent environment.

5. Combine with Other Diagnostics

The routing table tells you where traffic is directed, but not whether the path is working. Combine route print with ping (to test reachability) and tracert (to trace the actual path) for a complete diagnostic picture.

Conclusions

Displaying the Windows routing table with route print provides a master view of your system's networking logic. By moving beyond simple IP checking and understanding the map that guides your data, you gain the ability to troubleshoot complex connection drops, identify conflicting routes, optimize VPN performance, and verify that network changes were applied correctly. Filtering, saving snapshots, and understanding the meaning of each column transforms this simple command into a cornerstone of reliable network administration.