Manage Network Connections using Batch Scripts

Windows offer many different ways to manage your Network Connections including adapters status/configuration and network routing from the Command Line. The most frequently used are the Windows Management Instrumentation Command Line and the Netsh Command Line utility. Those commands can be used to automate Network Configuration in Batch Scripts.

List Available Network Interface Cards (NIC)

wmic nic get name,index,macaddress

Disable/Enable a NIC


wmic path win32_networkadapter where index=[Enter NIC Index here] call disable


wmic path win32_networkadapter where index=[Enter NIC Index here] call enable

You must run these commands as administrator, otherwise you may get a ReturnValue of 5. The default ReturnValue is 0, which means that no error occured.

List Network Connections

Using netsh you can view your Network Connections (both interface and IP configuration) using the command:

netsh interface ip show config

Set static/dynamic IP Address

Another way to list all the available interfaces beside wmic, is by using the command:

netsh interface show interface

After finding the name of the interface you want to set a Static IP Configuration, then run the command for the configuration you want:


netsh interface ipv4 set address "[Interface Name]" static address=[IP] mask=[Subnet Mask] gateway=[Gateway IP]


netsh interface ipv4 set address "[Interface Name]" dynamic

Route Specific Subnet to a specific NIC

You can view all active and persistent network routes using the command:

route print

This command also list the available NIC adapters (different index than previously with wmic), and from here you have to remember the index of the interface you want to route the traffic to.

Add a new route

Run the following command to reroute all the specified traffic to the specific NIC card

route ADD [Destination] MASK [Subnet Mask] [Gateway IP] IF [Interface Index in HEXADECIMAL]

So for example if we want to reroute all the traffic of the subnet with Gateway IP to the NIC Card with Decimal Index of 12 then the command should be:

route ADD MASK IF 0xC

Add a persistent route

After executing the previous command all the traffic to the network will be routed through the Network interface with the Index of 12, until next reboot. If you want to make the routing persistent you should use the -p flag as follows:

route -p ADD MASK IF 0xC
0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments





writing a dissertation abstract


dissertation thesis writing

dissertation proposal methodology example archived

dissertation proposal sample

dissertation help galway


citing a dissertation

writing a dissertation abstract

writing a phd dissertation


dissertation proposal sample


free vpn for fire stick


best torrent vpn


best vpn reddit

best vpn for 2017