Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change IP at logoff/shutdown 1

Status
Not open for further replies.

Kreichek

IS-IT--Management
Nov 15, 2005
28
DE
Hello. I would like the system to change its IP address, netmask and gateway at logout/shutdown to fixed values, so that it remains usable in the domain. Some people need to change them for testing purposes, but forget to put back the original ones and as a result users can't log on anymore and I have to change the address manually. Is there a way to make each machine remember its address at logon and if it changed at logoff/shutdown - change it back? Your help is appreciated.

---
Jordan Jordanov
Network administrator
Faculty of German Engineering Education and Industrial Management
Technical University of Sofia, Bulgaria
 
Give this scritp of mine a try. Users can save IP info as a configuration and switch between them. Should make life easier for you.

Code:
'==========================================================================
'
' NAME: IPSwitcher.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 3/23/2004
'
' COMMENT: This script and more are available in the Admin Script Pack 
'          [URL unfurl="true"]http://www.thespidersparlor.com/vbscript[/URL]
'
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================


Dim fso,WSHShell
Dim fso,WSHShell
 
 
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHSHell = CreateObject("Wscript.Shell")
Path = "C:\IPCONFIGS"
 
'Create Storage location if not already there
If Not fso.FolderExists(Path) Then
 fso.CreateFolder(Path)
End If
 
'Prompt to activate, create or delete a config
Action = InputBox("Do you want to ACTIVATE, SAVE or DELETE an IP Configuration","What should I do?")
Action = UCase(Action)
 
Call ConfigList
 
Select Case Action
 
Case "ACTIVATE"
     If Len(ConfigList) >0 Then
  What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter config name to activate.","Activate Which Configuration")
 FileName = Path & "\" & What & ".txt"
 WSHShell.Run ("cmd /c netsh -f " & FileName)
 Else
  MsgBox "Sorry there are no configurations to activate"
 End If
 
Case "SAVE"
 If Len(ConfigList) >0 Then
  What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter new config name to save, enter existing name to overwrite.","Save Configuration")
 Else
  What = InputBox("Enter new config name to save.","Save Configuration")
 End If 
 FileName = Path & "\" & What & ".txt"
 'MsgBox Filename
 WSHShell.Run ("cmd /c netsh -c interface dump >" & FileName)
 
Case "DELETE"
 If Len(ConfigList) >0 Then
  What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter config name to delete.","Delete Configuration")
  FileName = Path & "\" & What & ".txt"
  fso.DeleteFile(FileName)
 Else
  MsgBox "No configurations saved to delete."
 End If
 
End Select
MsgBox "Done"
 
Function ConfigList
'Read the existing configs
Set oFolder = fso.GetFolder(Path)
 
ThisList = ""  
For Each oFile In oFolder.files
 ThisConfigLength = (Len(oFile.Name)-4)
 ThisConfig = Left(oFile.Name,ThisConfigLength)
 ThisList = ThisList & ThisConfig & vbCrLf
Next
ConfigList = UCase(ThisList)
 
End Function

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Thanks, I think it will help.

---
Jordan Jordanov
Network administrator
Faculty of German Engineering Education and Industrial Management
Technical University of Sofia, Bulgaria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top