Windows : Add entire subnet in a batch

By | February 19, 2013

Adding a bunch of IP to windows through the GUI is a nightmare! Fortunately, you can enter a single command that will add them in a second.

Simply open the command prompt and type the following command :

FOR /L %I IN (<IP_START>,1,<IP_END>) DO netsh interface ip add address "Local Area Connection" <IP_SUBNET>.%I <IP_NETMASK>

Let’s explain every piece of that command :

<IP_START> would be the first usable IP of your range
<IP_END> would be the last usable IP of your range
<IP_SUBNET> is the first three numbers of your range
<IP_NETMASK> is your netmask

In a nutshell, suppose we want to add the following C class : 192.168.1.32/27 (which represent 32 IPs)
SUBNET IP : 192.168.1.32
USABLE IPs : 192.168.1.33 – 192.168.1.62
BROADCAST  : 192.168.1.63
NETMASK : 255.255.255.224

The command would be :

FOR /L %I IN (33,1,62) DO netsh interface ip add address "Local Area Connection" 192.168.1.%I 255.255.255.224

NOTE : If your changed the default interface name (Local Area Connection), you need to enter the new interface name between the double quotes.