#170559 - 2006-11-21 05:15 PM
Changing default gateway with NETSH
|
Brian Chivers
Fresh Scripter
Registered: 2002-08-15
Posts: 10
Loc: UK
|
I'm trying to write a script to change serveral machines default gateway. I've sucessfully done it with using the command below
netsh interface ip set address "Local Area Connection 2" gateway=192.168.0.2 gw=1
The problem I have is that not all the machines use the "Local Area Connection 2" name and as far as I can see netsh won't allow you to use a wildcard in the section after address so something like this
netsh interface ip set address * gateway=192.168.0.2 gw=1
If you type
netsh interface ip show config
you get
Configuration for interface "Local Area Connection 2" DHCP enabled: No IP Address: 192.168.200.101 SubnetMask: 255.255.0.0 Default Gateway: 192.168.0.2 GatewayMetric: 1 InterfaceMetric: 1 Statically Configured DNS Servers: 192.168.0.1 Statically Configured WINS Servers: None
What I think I need to do is to read in the first line and strip off all the info except for the "Local Area Connection 2" bit and then store this in a variable and pass this to the script.
Alternatively I could just run the script twice once against "Local Area Connection" & once again "Local Area Connection 2" and let it error out 
Any idea's or pointers would be gratefully received
Thanks Brian netsh interface ip set address "Local Area Connection 2" gateway=192.168.0.2 gw=1
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 407 anonymous users online.
|
|
|