Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


A little help with a script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,56910
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> A little help with a script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 A little help with a script - 2/20/2008 2:31:10 AM   
  lilalfyalien

 

Posts: 1
Score: 0
Joined: 2/20/2008
Status: offline
Hi,

I am new to VBScript and am trying to create a script to do the following:

Retrieve the computers IP address (the computers only have one network card)

If the IP address has not changed (begins with the octet "176") then change the first octet of computers' IP address to "172"

How could I do this?

I already have the code to change the Ip address but how to I get it/ chnage only the first octet?

Thanks in advance,

strComputer = "."
strConnection = "Local Area Connection"
strIP = Array("1.22.2.2")
strMask = Array("255.255.255.0")
strGatewayIP = Array("1.2.3.3")
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colNA = objWMI.ExecQuery("select * " & _
" from Win32_NetworkAdapter " & _
" where NetConnectionID = '" & strConnection & "'" )
for each objNA in colNA
set colNAConfig = objWMI.ExecQuery _
("ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='" & _
objNA.DeviceID & "'} " & _
" WHERE resultClass = win32_NetworkAdapterConfiguration ")
for each objNAConfig in colNAConfig
intRC = objNAConfig.EnableStatic(strIP,strMask)
intRC2 = objNAConfig.SetGateways(strGatewayIP)
if intRC = 0 and intRC2 = 0 then
WScript.Echo "IP address configured for " & strConnection
elseif intRC = 1 or intRC2 = 1 then
WScript.Echo "You must reboot for the changes to take effect for " & _
strConnection
else
WScript.Echo "There was an error configuring IP for " & _
strconnection & ": " & intRC & " and " & intRC2
end if
next
next

_____________________________

Lilalfyalien
 
 
Post #: 1
 
 RE: A little help with a script - 2/20/2008 2:36:00 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Well, you can find lots of examples of getting the current IP address either at this site or by searching on google. Once you have the current IP, use Split() to look at the first octet. Split() will essentially give you an array of the octets. Once you have the array you can change the first element of the array (the first octet) then use the array to set the IP address using the code that you already have.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to lilalfyalien)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> A little help with a script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts