Page 1 of 2 12>
Topic Options
#25489 - 2002-07-19 08:27 PM Default Gateway
Urooj Offline
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
#25490 - 2002-07-20 06:46 AM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... you don't say what OS those machines are. For Win2k, there's the NETSH command that'd do it without a reboot.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25491 - 2002-07-20 05:51 PM Re: Default Gateway
Urooj Offline
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
#25492 - 2002-07-20 05:57 PM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are enough UDFs posted to the lib to do just about anything IP related. Have you done a search?

Also, check out TechNet article Q194407.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25493 - 2002-07-20 06:46 PM Re: Default Gateway
Urooj Offline
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
#25494 - 2002-07-20 09:45 PM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Without an understanding on what boundaries you subnet, I can't really advise further. I subnet on class 'B' and 'C' boundaries so figuring out what submnet a machine is in is a cake walk.

Take a look at this UDF

Topic: CalcLogicalSubnet () - Returns the logical subnet ID
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25495 - 2002-07-20 11:19 PM Re: Default Gateway
Urooj Offline
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
#25496 - 2002-07-21 04:14 AM Re: Default Gateway
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The main probelm youare facing is that the default gateway is defined on a per-NIC basis in the computers registry. Therefore, you can either use NETSH for Windows 2000/XP or write a UDf that changes just the default gateway. You already got some of those pieces in our private email conversation. Additionally, you will need to make those changes under an administratvie account which means either scheduling it with the Task Scheduelr or using SU.EXE if the changes must be applied during the login process.

Therefore your script needs to do the following things.
1) Read in the computers IP address, e.g. IP=split(@IPADDRESS0,'.') will give you an array of four octets of the IP address.
2) Read from e.g. a .INI file the old/new gateway combinations. If the new gateway is based on the old gateway, make it
code:
[GatewayList]
OldGateway=NewGateway

otherwise do it e.g. based on network ID:
code:
[NetworkIDList]
NetworkID=NewGateway

2) Use any of the appropriate subnet UDFs to decide the new gateway IP.
3) Change the registry keys fro the computers NIC from the old gateway to the new one.

The UDF CheckNICS() that I sent you does those things. It does look complicated because it has to cover different operatings systems and thus different ways of storing the gateway info. It also has to be so generic as to work with any kind of NIC, who are all stored in different places in the registry.
_________________________
There are two types of vessels, submarines and targets.

Top
#25497 - 2002-07-21 05:21 AM Re: Default Gateway
Urooj Offline
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
#25498 - 2002-07-21 06:07 AM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why not just setup a translate table as Jens suggested. All it takes is an INI file as follows:

GW.INI
code:
[GATEWAY]
172.22.13.251=172.22.13.252

Then a bit of code as follows will do the trick:
code:
break on
$RC=ReadProfileString("C:\KiX4.02\GW.INI","GATEWAY","172.22.13.251")
$RC ?
Get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25499 - 2002-07-21 08:57 PM Re: Default Gateway
Urooj Offline
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
#25500 - 2002-07-21 11:17 PM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The flaw in your logic is that you're trying to compare a string to a value. Your IP octets are strings unless you convert them with Val().

The way to do it is as follows:
code:
$1st = Val(SUBSTR(@ipaddress0, 1, 3))
$2nd = Val(SUBSTR(@ipaddress0,5,3))
$3rd = Val(SUBSTR(@ipaddress0,9,3))
$4th = Val(SUBSTR(@ipaddress0,13,3))

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25501 - 2002-07-22 12:45 AM Re: Default Gateway
Urooj Offline
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
#25502 - 2002-07-22 03:45 AM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
To get the mask, you can try EnumIPinfo() or if that fails you, Howard's UDF GetIPinfo(). Jens has a whole bunch of UDFs as well.

If you plan to change the GW in the reg, then you'll need to figure out where it is. Once you get that figured out, you'll see the SubNet Mask is in the same reg key.

I still don't see why the INI route would be such a big deal. You only need to have entries for those that need to be changed. You certainly don't need 8000 entries unless you plan to change all of them. You could also use the INI file as a control file to determine what subnets need to be changed.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25503 - 2002-07-22 03:15 PM Re: Default Gateway
Sealeopard Offline
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 Offline
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
#25505 - 2002-07-25 11:54 PM Re: Default Gateway
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Move the GOTO parts into the CASE statements, there's no need to exit a CASE the way you do it since it'll go to the ENDSELECT automatically, anyway.
_________________________
There are two types of vessels, submarines and targets.

Top
#25506 - 2002-07-26 02:05 AM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The + on this line I don't understand.

$SBM=+EnumIPInfo(0,1)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25507 - 2002-07-26 02:07 AM Re: Default Gateway
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OH, and I don't see any ENDIFs for the IFs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25508 - 2002-07-26 05:15 PM Re: Default Gateway
Urooj Offline
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
Page 1 of 2 12>


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.073 seconds in which 0.049 seconds were spent on a total of 13 queries. Zlib compression enabled.

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