#25489 - 2002-07-19 08:27 PM
Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
I have a need to change the Default gateway on about 635 machines which are not using DHCP. They want to use HSRP . I have the list of machines and their current settings. All I need to do is change the Default gateway to the new HSRP address scheme. It only consists of changing the last Octet since most of my machines are on Class C networks.Here is the break down /26 Q1 .59/60 Q2 123/124 Q3 187/188 Q4 251/252 /25 1st half 123/124 2nd half 251/252 /24 .251 / .252 That would be ranges the machines would be in to use the HSRP standard. For example if the machine is has the following IP address 146.125.79.25 subnet 255.255.255.192 and It is in first Quad it would get 146.125.79.59 and 146.125.79.60 as the default gateways. Any suggestions Please help ...
|
|
Top
|
|
|
|
#25491 - 2002-07-20 05:51 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
The Machines vary from Windows NT to Windows 2000. I was thinking of getting an IP address breaking it down to the 4 octets and then taking the last Octet value compare it to a number and if that number is equal to or less than the gateway I want it would modify the registry to enter the desired gateway. Something like IF $IP4 <= 62 then write $IP1.$IP2.$IP3.60 as the default gateway. The only problem I have with that is if the subnet masks changes Then the above statement won't alway hold true.
|
|
Top
|
|
|
|
#25493 - 2002-07-20 06:46 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
I tried looking at the UDF library but no one really explained how those scripts fit into my problem. I saw one It couldn't make heads or toes of it. Want to combine some of the simple Scipts into one script to do my task. Take the following script Returns IP Address in usable form. $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 and Just do as I stated above compare the last Octet and subnet Mask to come up with something like this $NEWGateway = $IPPart1 + $IPPart2 +$IPPart3 +$HSRPGAteway Take this IP Address and write it into the registry for the gateway or use the Netsh command to change the gateway on Win 2k Machines.
|
|
Top
|
|
|
|
#25495 - 2002-07-20 11:19 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
I am currenlt only concerned with class C networks. I was thinking if we could read the registry or do an IPconfig to a text file where by reading the default gateway and subnet mask we could determine from those two pieces of information what the new default gateway should be. we have the following masks 255.255.255.0 255.255.255.128 255.255.255.192 255.255.255.224 these are the current subnet masks we use on our class C networks. I have about 600 machines on varies subnets maybe like 200 subnets which need to be modified to comply like I stated in the orginal post.
|
|
Top
|
|
|
|
#25497 - 2002-07-21 05:21 AM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Alright I kind of understand what you are saying. I was thinking of Using SMS to push out the Gateway changes. I created a Spread sheet with the following Header row Location Netbios Name Sites IP Address Subnet mask Default IP Gateway DHCP Enabled Configuration Needed T/F HSRP Changes Needed The list above is my header row. For example this would be found in this spreadsheet
222 Broadway ELVIS1 C08 172.22.13.1 255.255.255.0 172.22.13.251 0 T T HSRP=172.22.13.252 As you can see I need to change the following info 172.22.13.251 to 172.22.13.252 on the machine listed above. I was thinking along the lines take the IP Address (172.22.13.1) and Subnet Mask (255.255.255.0) By looking at the subnet mask If SBMAsk= 255.255.255.0 then the $NewDgateway =$ip1.$IP2.$IP3.252 If SBMASK= 255.255.255.192 then do the following Break the Ipadrress down into the 4 octets look at the last octet and do some kind of math operation $IP4 <=62 $NewGateway= $IP1.$IP2.$IP3.60 If 63=< $IP4 <=126 then NewDgateway= $IP1.$IP2.$IP3.124 And so on. Would that make any sense to do ? After which I can writeval the New gateway into the registry. Just an idea tell me if that is the wrong approach. I only have Windows NT 4 and Windows 2000 machines and very few Windows XP machines at the moment.
|
|
Top
|
|
|
|
#25499 - 2002-07-21 08:57 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Sorry to be a little slow with this but what I was thinking was that the script would change any class C gateway to the desired gateway. We have way too many subnets running here when I last checked it 8000 subents world wide. So instead of having a file with 8000 entries and translating them to the New gateway the script I was thinking of would do any subnet that we want to change even gateways which SMS might have missed identifiying. I will try to do what you guys suggested and see how it works but is there somthing wrong with my desired script too complicated or just doesn't make any sense ? Thanks for all your help guys.
|
|
Top
|
|
|
|
#25501 - 2002-07-22 12:45 AM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
So with the listed Function I should be able to compare the last Octet where by allowing me to finish the Script. Let me see I use SMS to push to the machines NT 4 and Windows 2000 maybe some Win XP machines. It checks for the IP address and Subnet Mask of the machine. Then it should convert the last Octet to a numeric value this is where I can run a math function and compare the number. After it gets that number it will perform the end result assigning the correct default gateways to the machines. Is there a speical function to get the default mask I see that IP can be obtained how about the subnet Mask ? Wouldn't this be a shorter script for class Ip addresses with a limited number of subnet Masks ?
|
|
Top
|
|
|
|
#25503 - 2002-07-22 03:15 PM
Re: Default Gateway
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
I have to agree with Les. First, you'll need to find the unique identifier that trigegrs the gateway change. For example if the new gateway depends on the old gateway, then you create a look-up table (preferable the .INI file because it's the easiest to read in Kixtart) with OldGatewya=NewGateway. If it is based on NetworkID/SubnetMask like 123.123.123.0/255.255.255.0 or 123.123.123.0/19 then you would use this like NetworkID/SubnetMask=NewGateway.
Nevertheless, you will still need to go through the registry, identify the NIC inthe particular computer, change the gateway, adn force a reboot of said computer. This is all independent of whether you distribute the script via SMS, Task Scheduler, SneakerNet,... [ 22 July 2002, 15:15: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#25504 - 2002-07-25 11:37 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
I have an update .... Take a look at my script and see if it makes any sense. Yes I know it only will work in a class C subnet and also on a machine with only one NIC card. I got to the point where I get the desired result now I just have to find a way to write the data back into the machine. I was thinking of using WMI , or using Netsh set command on teh W2k and WXP machines. The NT 4 machines I could use WMI or I could write to the registry. Please let me know what you guys think You really have been great Help Thanks. Afternoon I thought I give you guys an update on what I have come up with . Let me know if you see some kind of problem with it.
Break on $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 $SBM=+EnumIPInfo(0,1) $Octet = Val(SubStr(@ipaddress0,13,3)) If $SBM Select Case $SBM="255.255.255.0" Goto Oneseg Case $SBM="255.255.255.128" Goto Halfseg Case $SBM="255.255.255.192" Goto Quadseg Case $SBM="255.255.255.224" Goto 252 EndSelect :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 default gateway is address is "$NDG ?" Your default gateway is address is "$NDG1
|
|
Top
|
|
|
|
#25508 - 2002-07-26 05:15 PM
Re: Default Gateway
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Well I searched through the forum here and there was a posting by MCA which had the following syntax He used the +EnumIPInfo(0,1). I just followed his lead. I read on this Forum that this function doesn't really work under Windows NT 4. Is that correct ? If the problem hasn't been fixed in the latest build I will need to use something for that OS. I have a WMI script which should set the gateway
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) Next
I will make the changes you recommended below on the goto and the endif. But I really need to resolve how to write the default gateway into the machines.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|