How would I make a script using the netsh command that would...

CoolTech

Platinum Member
Jul 10, 2000
2,345
3
0
I need a script that does the following:

I have multiple machines that I want to change the ip addresses of periodically.

Example:

IP: 192.168.107.101
Gateway: 192.168.107.1

change to:

IP: 192.168.106.101
Gateway: 192.168.106.2

Basically, the 3rd octet of the IP and the 3rd and 4th octets of the subnet needs to be changed, and I would like to do this via a script that would change the 107 value to 106 for the IP and the subnet from "107.1" to "106.2" via a wildcard or something. Since this is just an example, I just need a wildcard of some sort to be able to change the 3rd and 4th octets of the IP address. Is this possible via the netsh command and a batch file?
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
yes....you have to specify the entire netsh command, i.e.
netsh dhcp server 10.10.10.10 scope scope1 add reservations name m.a.c

you can't write the batch file like
netsh
dhcp
server
10.10.10.10

etc. Like you can at the command line (basicly netsh stops reading the batch file) do a netsh /? for help. I just wrote a script to add 300 static reservations, so I know that it works.
 

CoolTech

Platinum Member
Jul 10, 2000
2,345
3
0
also, when I say periodically, I mean they want to use a different program from time to time which requires them to use a different subnet
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
I was using the DHCP as an example. Netsh has differnet contexts. You must specify the full context in a single line of your batch file.

netsh <context><change1>
netsh <context><change2>
etc