#25510 - 2002-07-26 08:36 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Thanks for the info I was seeing that problem being discussed on the boards here. Well Here is a modified script does this make any sense to do ?
Break On $hklm='HKEY_LOCAL_MACHINE' select case instr(@PRODUCTTYPE,'Windows NT') $OS_SHORT='WinNT' case instr(@PRODUCTTYPE,'Windows 2000') $OS_SHORT='Win2K' case instr(@PRODUCTTYPE,'Windows XP') $OS_SHORT='WinXP' case 1 return endselect
$tempfile = "%temp%\ipconfig.tmp" Shell '%comspec% /c ipconfig /all | find /i "Subnet Mask" >"$tempfile" 2>nul' If Open(1,$tempfile) = 0 $line = ReadLine(1) $SBNM = Ltrim(SubStr($line,InStr($line,":")+1)) ?"Subnet Mask=" $SBNM EndIf $IpPart1 = Ltrim(SubStr(@IPADDRESS0, 1, 4)) $IpPart2 = Ltrim(SubStr(@IPADDRESS0, 5, 4)) $IpPart3 = Ltrim(SubStr(@IPADDRESS0, 9, 4)) $IpPart4 = Ltrim(SubStr(@IPADDRESS0, 13, 3)) $IPAddressComplete = $IpPart1 + $IpPart2 + $IpPart3 + $IpPart4 $IPSUBN=$IpPart1 + $IpPart2 + $IpPart3 $Octet = Val(SubStr(@ipaddress0,13,3)) If $SBNM Select Case $SBNM="255.255.255.0" Goto Oneseg Case $SBNM="255.255.255.128" Goto Halfseg Case $SBNM="255.255.255.192" Goto Quadseg Case $SBNM="255.255.255.224" Goto 252 EndSelect Endif :Oneseg $NDG=$IPSUBN + 252 $NDG1=$IPSUBN + 251 Goto end :Halfseg Select Case $Octet<=126 $NDG=$IPSUBN + 124 $NDG1=$IPSUBN + 123 Case $Octet<=254 $NDG=$IPSUBN + 251 $NDG1=$IPSUBN + 252 EndSelect Goto end :Quadseg If $OCTET Select Case $Octet<= 62 $NDG=$IPSUBN + 60 $NDG1=$IPSUBN + 59 Case $Octet<=126 $NDG=$IPSUBN + 124 $NDG1=$IPSUBN + 123 Case $Octet<=190 $NDG=$IPSUBN + 188 $NDG1=$IPSUBN + 187 Case $Octet<=254 $NDG=$IPSUBN + 251 $NDG1=$IPSUBN + 252 EndSelect :252 :end
?" Your HSRP default gateway should be the following "$NDG ?" Your 2nd HSRP default gateway should be the following "$NDG1 ? " Your Os is "@PRODUCTTYPE ? " The Script will make the changes for you " Select Case $OS_SHORT='WinNT' ; this is where I would like to put in the command to write the NDG and NDG1 into the Windows NT 4 machines network settings case $OS_SHORT='Win2K' ; This is where a Windows 2000 machine would get the NDG and NDG1 written into in network settings area under Default gateway case $OS_SHORT='WinXP' ; This is where we would put the command need to update the machine with the new default gateways. Do you know how to set IP configuration in W2k and Wxp using the Netsh command ?
|
|
Top
|
|
|
|
#25512 - 2002-07-29 04:50 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Good Morning I cleaned up the script as the board suggested. Here is what I have been able to get this script to. Thanks again for all your help but will this work. I am thinking of combining WMI and Kix to achive the desired result. Take a look at the final script which should set the default gateways of my machines based on the subnet Mask.
code:
Break On $hklm='HKEY_LOCAL_MACHINE' Select Case InStr(@PRODUCTTYPE,'Windows NT') $OS_SHORT='WinNT' Case InStr(@PRODUCTTYPE,'Windows 2000') $OS_SHORT='Win2K' Case InStr(@PRODUCTTYPE,'Windows XP') $OS_SHORT='WinXP' Case 1 Return EndSelect $tempfile = "%temp%\ipconfig.tmp"
Shell '%comspec% /c ipconfig /all | find /i "Subnet Mask" >"$tempfile" 2>nul'
If Open(1,$tempfile) = 0 $line = ReadLine(1) $SBNM = Ltrim(SubStr($line,InStr($line,":")+1)) ?"Subnet Mask=" $SBNM EndIf
$IpPart1 = Ltrim(SubStr(@IPADDRESS0, 1, 4)) $IpPart2 = Ltrim(SubStr(@IPADDRESS0, 5, 4)) $IpPart3 = Ltrim(SubStr(@IPADDRESS0, 9, 4)) $IpPart4 = Ltrim(SubStr(@IPADDRESS0, 13, 3)) $IPAddressComplete = $IpPart1 + $IpPart2 + $IpPart3 + $IpPart4 $IPSUBN=$IpPart1 + $IpPart2 + $IpPart3 $Octet = Val(SubStr(@ipaddress0,13,3))
If $SBNM Select Case $SBNM='255.255.255.0' $NDG=$IPSUBN + '252' $NDG1=$IPSUBN + '251' Case $SBNM='255.255.255.128' Select Case $Octet<=126 $NDG=$IPSUBN + '124' $NDG1=$IPSUBN + '123' Case $Octet<=254 $NDG=$IPSUBN + '251' $NDG1=$IPSUBN + '252' EndSelect Case $SBNM='255.255.255.192' Select Case $Octet<=62 $NDG=$IPSUBN + '60' $NDG1=$IPSUBN + '59' Case $Octet<=126 $NDG=$IPSUBN + '124' $NDG1=$IPSUBN + '123' Case $Octet<=190 $NDG=$IPSUBN + '188' $NDG1=$IPSUBN + '187' Case $Octet<=254 $NDG=$IPSUBN + '251' $NDG1=$IPSUBN + '252' EndSelect Case $SBNM='255.255.255.224' ; nothing EndSelectEndif
?" Your default gateway is address is "$NDG ?" Your default gateway is address is "$NDG1 ? " Your Os is "@PRODUCTTYPE Select
Case $OS_SHORT='WinNT'
Case $OS_SHORT='Win2K' ;netsh interface ip Set adrress "@ipaddress0" "$SBNM" "$NDG" Case $OS_SHORT='WinXP' ;netsh interface ip Set adrress "@ipaddress0" "$SBNM $NDG"
$strComputer = "." $ObjWMIservice = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2") $colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") For Each $objNetAdapter in $colNetAdapters $errGateways = $objNetAdapter.SetGateways($NDG, 1) Next Exit1
The WMI part I am too sure about but it does seem to make sense a little bit ?
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|