Change IP script

Microsoft Windows xp professional w/serv...
May 28, 2010 at 05:00:14
Specs: XP pro, 1G
Got a script to change IP address below but the Network card has to be called "Local Area Connection" I notice on some machines it's called Local Area Connection 2 or Local Area Connection 3, how to I change the script to allow this without adding Local Area Connection 2 and Local Area Connection 3 in the command?


Dim strIPAddress
Dim strSubnetMask
Dim strGateway
Dim intGatewayMetric
Dim strDns1
Dim strDns2

strIPAddress = ""
strSubnetMask = ""
strGateway = ""
intGatewayMetric = 1
strDns1 = ""
strDns2 = ""

Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True
Set objShell = Nothing

See More: Change IP script

Report •

May 28, 2010 at 09:35:09
Ok, I would like to ask first why you need to make this script. Is it that you have two subnets (or gateways) and you want to change back and forward between them?

If so I suggest that you don't use script to do this but rather setup alternative routes in the local routing tables using the route command. We have two gateways here and our programmers keeping using scripts to change their TCP/IP stacks when is easier to setup persistent routes. This is why I ask.

Oh and to solve your problem, I suggest you pull the NIC names from the IPCONFIG result.

Report •

May 28, 2010 at 18:10:27
We have laptops that is docked to a station which uses fixed internal IPs and when the users un-dock it to go to another room using wireless which uses DHCP, but for some reason when on some laptops it has changed to DHCP so they get 2 DHCP ips for the wireless and LAN, I just want a script when the machine starts up the fix ip is set to the LAN. I suspect the users takes their laptops home and connected to their home network and change it to DHCP and when they come back to work it is like that. But some laptops I see the Lan card is Local Area Connection or Local Area Connection 2 or Local Area Connection 3. So the scirpt needs to make sure it will apply to these names. Any sugguestions?

Report •

Related Solutions

Ask Question