Page 1 of 1 1
Topic Options
#9251 - 2001-06-06 01:22 AM Checking for Static IP and changing the IP if it is static.
Anonymous
Unregistered


Newbie to kixtart (2days old)
Anyone have any suggestions for a script that will check if a system has a static IP and if so, change it from a pre-defined scope of IP's? I have had absolutley no luck with this....
Thanks!

Top
#9252 - 2001-06-06 04:31 PM Re: Checking for Static IP and changing the IP if it is static.
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
tense -
I use this for single-NIC systems. Not fully set for Win2K devices, but should help you out. Items 1-3 used in DHCP section of my script, so I included here for you. Item 1 is where I define script-wide variables to certain registry keys. Item 2 defines O/S level of client and if Domain Controller. Item 3 defines user rights on workstation for WinNT/2K devices.
Bill

code:

; REM ** 1. Set reusable variables for Current Control Set registry key, Windows Current Version key, and installed NIC
$HKLMAPPS = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths"
SELECT
CASE (@INWIN = 1)
$HKLMSS = READVALUE ("HKEY_LOCAL_MACHINE\SYSTEM\Select", "Current")
$CurCtrStr = "ControlSet00"+$HKLMSS
$HKLMSCCS = "HKEY_LOCAL_MACHINE\System\$CurCtrStr"
$HKCUSMWCV = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion"
$HKLMSMWCV = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion"
$NetCard = ENUMKEY ("$HKLMSCCS\Services\NetBT\Adapters", 0)
CASE (@INWIN = 2)
$HKCUCP = "HKEY_CURRENT_USER\Control Panel"
$HKCUSMWCV = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion"
$HKCUSMWCVP = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies"
$HKLMSCCS = "HKEY_LOCAL_MACHINE\System\CurrentControlSet"
$HKLMSMWCV = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion"
ENDSELECT


; REM ** 2. Determine O/S type and version level, and determine role of the Win2K/WinNT system
SELECT
CASE (@INWIN = 1)
$OSDir = READVALUE ("$HKLMSMWCV", "SystemRoot")
$OSKey = ""
$OSNam = ""
$OSPid = READVALUE ("$HKLMSMWCV", "ProductId")
$OSSvc = READVALUE ("$HKLMSMWCV", "CSDVersion")
$OSVer = READVALUE ("$HKLMSMWCV", "CurrentVersion")
$OSTyp = UCASE (READVALUE ("$HKLMSCCS\Control\ProductOptions", "ProductType")) ; REM ** NT Server role.
$OSSui = UCASE (READVALUE ("$HKLMSCCS\Control\ProductOptions", "ProductSuite")) ; REM ** Enterprise & Terminal Server.


SELECT
CASE (@DOS >= 5.0) $OS = "Win2K" $OSLvl = "Pro" $OSNam = "Microsoft Windows 2K" $WinDC = "1"
CASE (1) $OS = "WinNT" $OSLvl = "Wksta" $OSNam = "Microsoft Windows NT" $WinDC = "1"
ENDSELECT


SELECT
CASE ($OSTyp="LANMANNT") $OSLvl = "Domain Controller" $WinDC = "0"
CASE ($OSTyp="SERVERNT") $OSLvl = "Member Server" $WinDC = "0"
ENDSELECT
$OSAbv = $OS


CASE (@INWIN = 2)
; REM ** Ver info from MS Tech Article Q158238: "How to Determine Version of Win95/98/ME in Use" (2001.04.10)
$OS = "Win9x"
$OSDir = READVALUE ("$HKLMSMWCV", "SystemRoot")
$OSKey = READVALUE ("$HKLMSMWCV", "ProductKey")
$OSNam = READVALUE ("$HKLMSMWCV", "ProductName")
$OSPid = READVALUE ("$HKLMSMWCV", "ProductId")
$OSVer = READVALUE ("$HKLMSMWCV", "VersionNumber")
$OSSvc = LTRIM (RTRIM (UCASE (READVALUE ("$HKLMSMWCV", "SubVersionNumber"))))
$WinDC = "1"
SELECT
CASE ($OSVer >= "4.90.3000") $OSAbv = "WinME" $OSLvl = "OEM"
CASE ($OSVer >= "4.10.2222") $OSAbv = "Win98" $OSLvl = "SE"
CASE ($OSVer >= "4.10.1998") $OSAbv = "Win98" $OSLvl = "OEM"
CASE (($OSVer >= "4.03.1214") AND ($OSSvc = "C")) $OSAbv = "Win95" $OSLvl = "SR 2.5"
CASE (($OSVer >= "4.03.1212") AND ($OSVer =< "4.03.1214")) $OSAbv = "Win95" $OSLvl = "SR 2.1"
CASE ($OSVer >= "4.00.1111") $OSAbv = "Win95" $OSLvl = "SR 2"
CASE (($OSVer >= "4.00.950") AND ($OSSvc = "A")) $OSAbv = "Win95" $OSLvl = "SP 1"
CASE ($OSVer >= "4.00.950") $OSAbv = "Win95" $OSLvl = "OEM"
CASE (1) $OSAbv = "Unknown" GOSUB ScriptError EXIT
ENDSELECT
CASE (1) $OSAbv = "Unknown" GOSUB ScriptError EXIT
ENDSELECT


; REM ** 3. Define_user privilege. Note: For 'INGROUP \\@WKSTA' to work properly you must create a Global Domain group,
; REM ** add Admin/Power Users to this group, then add the Global group to local workstation Admin/Power Users groups.
SELECT
CASE INGROUP ("Domain Admins") $Privilege = "Domain Admin"
CASE INGROUP ("\\@WKSTA\Administrators") $Privilege = "Local Admin"
CASE INGROUP ("\\@WKSTA\Power Users") $Privilege = "Power User"
CASE (1) $Privilege = "User"
ENDSELECT


:CheckDHCP
; rem ###########################################################################
; rem ## Checks to make sure that the DHCP settings are correct. ##
; rem ## If incorrect the script edits the registery to insert the correct ##
; rem ## values. If the script has problems doing so (general error, ##
; rem ## user dosen't have rights to modify the registry, etc.) a message ##
; rem ## is sent to the system administrators alerting them to this fact. ##
; rem ## ; rem ###########################################################################

; REM ** Local variables in use by this function are:
$DsplyMsg = "Your DHCP settings have been updated."
$EmailMsg = "DHCP settings updated on computer @WKSTA."
$ErrorMsg = "Could not update the DHCP settings on your workstation. A system administrator has been notified."
$NicYN = 0


; REM ** Finds the various current DHCP settings. Script set for single-NIC system only.
SELECT
CASE (($WinDC = "0") OR ($OS = "Win2K"))
$Console = WRITELINE (10, "$AbortMsg" + $CR)
$Status = $Abort
RETURN
CASE (($OS = "WinNT") AND ($Privilege = "User"))
$Console = WRITELINE (10, "User does not have permissions to change DHCP settings." + $CR)
GOSUB ScriptError
RETURN
CASE ($OS = "WinNT")
$KeyName = ENUMKEY ("$HKLMSMWCV\NetworkCards\", 0)
$NicType = READVALUE ("$HKLMSMWCV\NetworkCards\$KeyName","ServiceName")
$DhcpVal = READVALUE ("$HKLMSCCS\Services\$NicType\Parameters\TCPIP","EnableDHCP")
$ChkKey = ("$HKLMSCCS\Services\$NicType\Parameters\TCPIP")
CASE (1)
$KeyName = ENUMKEY ("$HKLMSCCS\Services\Class\NetTrans\" , $Index)
$ChkKey = ("$HKLMSCCS\Services\Class\NetTrans\$KeyName")
ENDSELECT


$IPVal = READVALUE ("$ChkKey", "IPAddress")


SELECT
CASE ((@INWIN = 1) AND ($DhcpVal <> "1")) GOSUB DHCP_SET
CASE ($IPVal <> "0.0.0.0") GOSUB DHCP_SET
CASE (1)
$Console = WRITELINE (10, "Verified DHCP Settings: $IPVal" + $CR)
$Status = $OK
ENDSELECT
RETURN


:DHCP_SET
$RegKey = "$HKLMSCCS\Services"
SELECT
CASE ($OS = "Win2K")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "EnableDHCP" , "1" , "REG_DWORD")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "IPAddress" , "0.0.0.0" , "REG_MULTI_SZ")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "SubnetMask" , "0.0.0.0" , "REG_MULTI_SZ")
$Console = WRITEVALUE ("$RegKey\DHCP" , "Start" , "2" , "REG_DWORD")
; $Console = WRITEVALUE ("$RegKey\NetBT\Parameters\Interfaces\Tcpip_$NicType" , "NameServerList" , "" , "REG_MULTI_SZ") ; REM ** WINS Servers IPs
$Console = WRITEVALUE ("$RegKey\NetBT\Parameters" , "EnableDNS" , "1" , "REG_DWORD")
CASE ($OS = "WinNT")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "EnableDHCP" , "1" , "REG_DWORD")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "IPAddress" , "0.0.0.0" , "REG_MULTI_SZ")
$Console = WRITEVALUE ("$RegKey\$NicType\Parameters\TCPIP" , "SubnetMask" , "0.0.0.0" , "REG_MULTI_SZ")
$Console = WRITEVALUE ("$RegKey\DHCP" , "Start" , "2" , "REG_DWORD")
; $Console = WRITEVALUE ("$RegKey\NetBT\Adapters\$NicType" , "NameServer" , "" , "REG_SZ") ; REM ** WINS Server1 IP
; $Console = WRITEVALUE ("$RegKey\NetBT\Adapters\$NicType" , "NameServerBackup" , "" , "REG_SZ") ; REM ** WINS Server2 IP
$Console = WRITEVALUE ("$RegKey\NetBT\Parameters" , "EnableDNS" , "1" , "REG_DWORD")
CASE (1)
$Console = WRITEVALUE ("$RegKey\Class\NetTrans\$KeyName" , "IPAddress" , "0.0.0.0" , "REG_SZ")
$Console = WRITEVALUE ("$RegKey\Class\NetTrans\$KeyName" , "IPMask" , "0.0.0.0" , "REG_SZ")
DELVALUE ("$RegKey\VxD\MSTCP" , "NodeType")
DELVALUE ("$RegKey\VxD\MSTCP" , "ScopeID")
ENDSELECT


$IPVal = READVALUE ("$ChkKey", "IPAddress")
SELECT
CASE ($IPVal = "0.0.0.0")
$Console = WRITELINE (10, "Updated DHCP Settings: $IPVal" + $CR)
$Reboot = "DHCP"
$Status = $Updat
CASE (1)
$Console = WRITELINE (10, "Failure verifying DHCP Settings." + $CR)
GOSUB ScriptError
ENDSELECT
RETURN


[This message has been edited by bleonard (edited 06 June 2001).]

Top
#9253 - 2001-06-06 05:49 PM Re: Checking for Static IP and changing the IP if it is static.
Anonymous
Unregistered


Hhmm!

Great piece of code there dude...!

------------------
A l l Y o u r K I X A r e B e l o n g T o U s ! ! !

Top
#9254 - 2001-06-06 05:53 PM Re: Checking for Static IP and changing the IP if it is static.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
The Canadian judge gives that a ...

-Shawn

Top
#9255 - 2001-06-07 12:30 AM Re: Checking for Static IP and changing the IP if it is static.
Anonymous
Unregistered


WOW!
Much advanced for me....
heh, another problem is I dont have single nic systems....there are probally 4-5 different nics!

Top
#9256 - 2001-06-07 12:57 AM Re: Checking for Static IP and changing the IP if it is static.
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
tense -
For multiple NIC's your could create loop structure under section 4 that looks at $KeyName and $NicType variables, changing the value '0' upward.

Have not tested, since not my configs, but again should point you in the right direction. Perhaps someone else on the board has solved this item?

Bill

Top
#9257 - 2001-06-07 08:26 PM Re: Checking for Static IP and changing the IP if it is static.
Anonymous
Unregistered


Thanks to all that replied! I cam up with a way to do it......I will post the code as soon as I get home!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1077 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.053 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org