Change IP LogIn Script Help *please*;)
#1
Scooby Regular
Thread Starter
Change IP LogIn Script Help *please*;)
Calling the Power of Scoobynet
I need to change the static IP's of about 150 pcs on our network, and the associated Hosts file - something like this:-
m\c W1A gets IP 10.2.1.1
m\c W1B gets IP 10.2.1.2
m\c W1C gets IP 10.2.1.3
etc
m\c W2A gets IP 10.2.2.1
m\c W2B gets IP 10.2.2.2
m\c W2C gets IP 10.2.2.3
I know you can use NETSH with W2k & XP - see example:-
:: Set the IP address.
netsh interface ip set address "Local Area Connection"
static 192.168.1.10 255.255.255.0 192.168.1.1 1
netsh interface ip set dns "Local Area Connection"
static 192.168.1.2
but i need it to 'look up' the m\c name and choose the correct IP from the list, using a TXT file or similar. HELP!
I could have one script per block i.e W1's W2's W3's
I reckon changing the HOSTS file should be easy such as:
if exists "C:\windows\drivers\system32\drivers\hosts copy \\server\hosts C:\windows\drivers\system32\drivers\hosts"
if exists "C:\winnt\drivers\system32\drivers\hosts copy \\server\hosts C:\winnt\drivers\system32\drivers\hosts"
all the PC's are mainly W2k or XP (occasional NT but I can do these few manually if needed) using NT4 domain server
Actually could probably use %root% on the above example to save having to have two lines
And don't even mention DHCP - i know, i know - but my IT director doesnt
SO anybody got any help with this script - beg beg
I need to change the static IP's of about 150 pcs on our network, and the associated Hosts file - something like this:-
m\c W1A gets IP 10.2.1.1
m\c W1B gets IP 10.2.1.2
m\c W1C gets IP 10.2.1.3
etc
m\c W2A gets IP 10.2.2.1
m\c W2B gets IP 10.2.2.2
m\c W2C gets IP 10.2.2.3
I know you can use NETSH with W2k & XP - see example:-
:: Set the IP address.
netsh interface ip set address "Local Area Connection"
static 192.168.1.10 255.255.255.0 192.168.1.1 1
netsh interface ip set dns "Local Area Connection"
static 192.168.1.2
but i need it to 'look up' the m\c name and choose the correct IP from the list, using a TXT file or similar. HELP!
I could have one script per block i.e W1's W2's W3's
I reckon changing the HOSTS file should be easy such as:
if exists "C:\windows\drivers\system32\drivers\hosts copy \\server\hosts C:\windows\drivers\system32\drivers\hosts"
if exists "C:\winnt\drivers\system32\drivers\hosts copy \\server\hosts C:\winnt\drivers\system32\drivers\hosts"
all the PC's are mainly W2k or XP (occasional NT but I can do these few manually if needed) using NT4 domain server
Actually could probably use %root% on the above example to save having to have two lines
And don't even mention DHCP - i know, i know - but my IT director doesnt
SO anybody got any help with this script - beg beg
#4
Scooby Regular
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
Code:
' Read Machine Names from file specified below in the format: machinename,Ipaddress with one machine per line ' David Wallis 06/04/2004 Const ForReading = 1 strSubnetMask = Array("255.255.255.0") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) strFileName = "p:\machines.txt" Set objNetwork = CreateObject("WScript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile (strFileName, ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline strMachineName = Mid(strNextLine,1,(InStr(1,UCase(Trim(strNextLine)),",")-1)) If strMachineName = UCase(objNetwork.ComputerName) Then strIp = Mid(strNextLine,(InStr(1,UCase(Trim(strNextLine)),",")+1),Len(strNextLine)) Wscript.echo "Match Found for " & strMachineName & " " & strIp strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array(strIp) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next End If Loop
#5
Scooby Regular
Thread Starter
Blimey - Thanks a lot, it looks fabulous - I won't try and fool you into knowing what the hell it does - its mostly double dutch to me!
How do I format my TXT file?
W1A,10.2.0.1,W1B,10.2.0.2,W1C,10.2.0.3....etc
or another way?
and do I need to run it for each block, W1's W2's or does it do it in one big file?
Thanks again!
How do I format my TXT file?
W1A,10.2.0.1,W1B,10.2.0.2,W1C,10.2.0.3....etc
or another way?
and do I need to run it for each block, W1's W2's or does it do it in one big file?
Thanks again!
#7
Scooby Regular
Thread Starter
yep - tried it on my PC this afternoon and it works great - thanks! Just need to build the full TXT file & set the Login Script for all the users now.
I tried to add the pri DNS setting in to the script but it didnt work:-
I put in:-
define the Dns str variable at the top of the script a la Gateway & subnet
strDns = Array("195.183.89.230")
then near the bottom after the errGateways line:
errDns = objNetAdapter.SetDns(strDns, strDnsmetric)
I'm guessing its just a syntax problem as the DNS has a primary & secondary value - or am I going about this the wrong way.....
Thanks again for all your help - you've saved me some serious shoe leather here!
I tried to add the pri DNS setting in to the script but it didnt work:-
I put in:-
define the Dns str variable at the top of the script a la Gateway & subnet
strDns = Array("195.183.89.230")
then near the bottom after the errGateways line:
errDns = objNetAdapter.SetDns(strDns, strDnsmetric)
I'm guessing its just a syntax problem as the DNS has a primary & secondary value - or am I going about this the wrong way.....
Thanks again for all your help - you've saved me some serious shoe leather here!
Trending Topics
#9
Scooby Regular
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
try....
Code:
' Read Machine Names from file specified below in the format: machinename,Ipaddress with one machine per line ' David Wallis 06/04/2004 Const ForReading = 1 strSubnetMask = Array("255.255.255.0") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) strDNSServerSearchOrder = Array("192.168.0.123","192.168.1.123") strFileName = "p:\machines.txt" Set objNetwork = CreateObject("WScript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile (strFileName, ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline strMachineName = Mid(strNextLine,1,(InStr(1,UCase(Trim(strNextLine)),",")-1)) If strMachineName = UCase(objNetwork.ComputerName) Then strIp = Mid(strNextLine,(InStr(1,UCase(Trim(strNextLine)),",")+1),Len(strNextLine)) Wscript.echo "Match Found for " & strMachineName & " " & strIp strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array(strIp) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNSServerSearchOrder) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next End If Loop
Thread
Thread Starter
Forum
Replies
Last Post
Sam Witwicky
Engine Management and ECU Remapping
17
13 November 2015 10:49 AM