Windows:批量添加整个子网

时间:2020-02-23 14:45:32  来源:igfitidea点击:

使用图形界面向Windows添加一堆IP是一场噩梦!幸运的是,您可以输入一个命令,将在一秒钟内添加它们。

只需打开命令提示符并执行以下命令:

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

让我们解释一下该命令的每一部分:

<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

简而言之,假设我们要添加以下C类:192.168.1.32/27(代表32个IP)子网IP:192.168.1.32可用IP:192.168.1.33 192.168.1.62 BROADCAST:192.168.1.63 NETMASK:255.255.255.224

该命令将是:

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

注意:如果您更改了默认的接口名称(本地连接),则需要在双引号之间输入新的接口名称。