Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Change IP LogIn Script Help *please*;)

Thread Tools
 
Search this Thread
 
Old 06 April 2004, 01:57 PM
  #1  
Dr Hu
Scooby Regular
Thread Starter
 
Dr Hu's Avatar
 
Join Date: Jul 1999
Location: Shropshire
Posts: 2,831
Received 24 Likes on 23 Posts
Question 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
Old 06 April 2004, 02:00 PM
  #2  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
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
Default

easy...

Mail me

David.wallis@ventura-uk.com
Old 06 April 2004, 02:17 PM
  #3  
Dr Hu
Scooby Regular
Thread Starter
 
Dr Hu's Avatar
 
Join Date: Jul 1999
Location: Shropshire
Posts: 2,831
Received 24 Likes on 23 Posts
Talking

Thanks for the swift post -

YHM
Old 06 April 2004, 02:46 PM
  #4  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
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
Default

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
Old 06 April 2004, 03:17 PM
  #5  
Dr Hu
Scooby Regular
Thread Starter
 
Dr Hu's Avatar
 
Join Date: Jul 1999
Location: Shropshire
Posts: 2,831
Received 24 Likes on 23 Posts
Default

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!
Old 06 April 2004, 07:40 PM
  #6  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
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
Default

machinea,10.0.0.1
computera,10.0.0.2
fred,192.168.0.1

run it for each block??? eh?
Old 06 April 2004, 11:25 PM
  #7  
Dr Hu
Scooby Regular
Thread Starter
 
Dr Hu's Avatar
 
Join Date: Jul 1999
Location: Shropshire
Posts: 2,831
Received 24 Likes on 23 Posts
Question

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!
Old 07 April 2004, 10:39 AM
  #8  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
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
Default

dns doesnt have a metric for a start.

David
Old 07 April 2004, 10:46 AM
  #9  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
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
Default

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
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Sam Witwicky
Engine Management and ECU Remapping
17
13 November 2015 10:49 AM
Ganz1983
Subaru
5
02 October 2015 09:22 AM
IAN WR1
ScoobyNet General
8
28 September 2015 08:14 PM
shorty87
Other Marques
0
25 September 2015 08:52 PM



Quick Reply: Change IP LogIn Script Help *please*;)



All times are GMT +1. The time now is 03:44 PM.