#19172 - 2002-03-27 05:54 PM
Using Select/Case and OR
|
Anonymous
Anonymous
Unregistered
|
I have not been able to find an answer on this question on the board so here goes...I am using SELECT to have a user sync up with the proper time server based on their IP address. Since there are only five time zones in Canada, I only want to have five cases in the statement, and not one case for every subnet.
To do this I am hoping that it is possible to group as follows:
$subnet = val(substr(@ipaddress0, 9, 3)) select case $subnet = 192 or 193 or 194 or 197 ;Pacific ? "Pacific" $home = "yvr01-nts-01" case $subnet = 189 or 190 ;Central ? "Central" ? $subnet $home = "ywg01-nts-01" case $subnet = 1 or 10 or 20 or 22 or 23 or 24 or 29 or 50 or 60 or 61 or 94 ;Eastern ? "Eastern" $home = "ykf01-nts-02" case $subnet = 80 or 91 or 92 or 93 ;Atlantic ? "Atlantic" $home = "yyy01-nts-01" case $subnet = 90 ;Newfoundland and Labrador ? "Newfoudland" $home = "yhz01-nts-01" case 1 ;Default to Mountain ? "Mountain" $home = "yeg01-nts-02" endselect
settime "$home"
____________________________________________
Somehow, it always chooses the first case in the select statement even though my IP address should be taking me to case 1. Is it possible to use case with or multiple time?
|
|
Top
|
|
|
|
#19173 - 2002-03-27 06:37 PM
Re: Using Select/Case and OR
|
Anonymous
Anonymous
Unregistered
|
I don't know if this will help you or not, but here's some code I wrote to break each part of the IP address in to a variable. I think it might make things easier.
; Calculates which octet/site the users is logging in from. $OCT1 = LTRIM(substr(@ipaddress0,1,3)) $OCT2 = LTRIM(substr(@ipaddress0,5,3)) $OCT3 = LTRIM(substr(@ipaddress0,9,3)) $OCTTOTAL = $OCT1+$OCT2+$OCT3
Here's how I use that code later on in my script:
IF INSTR ("$OCTTOTAL", "1020212") OR INSTR ("$OCTTOTAL", "102020") [ 27 March 2002, 18:41: Message edited by: MikeT ]
|
|
Top
|
|
|
|
#19174 - 2002-03-27 07:06 PM
Re: Using Select/Case and OR
|
Anonymous
Anonymous
Unregistered
|
Very Nice! I will definately get som use out of that.
|
|
Top
|
|
|
|
#19175 - 2002-03-27 07:15 PM
Re: Using Select/Case and OR
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Here is another method you could also try.
code:
SELECT CASE (SUBSTR(@IPADDRESS0,1,11)) = "125.111.142" ;code to set time to server in that region CASE (SUBSTR(@IPADDRESS0,1,11)) = "125. 26.115" ;code to set time to server in that region CASE (SUBSTR(@IPADDRESS0,1,11)) = "125. 10. 40" ;code to set time to server in that region CASE (SUBSTR(@IPADDRESS0,1,11)) = "105.110.120" ;code to set time to server in that region CASE (SUBSTR(@IPADDRESS0,1,7)) = "145. 15" ;code to set time to server in that region CASE (SUBSTR(@IPADDRESS0,1,7)) = "130.147" ;code to set time to server in that region CASE 1 ; Don't know your IP range, so won't do anything. just log it ENDSELECT
|
|
Top
|
|
|
|
#19177 - 2002-03-27 08:33 PM
Re: Using Select/Case and OR
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Your problem is syntax related.
case $subnet = 192 or 193 or 194 or 197 ;Pacific
should be: $subnet=192 or $subnet=193 or $subnet=194 or $subnet=197
You may also want to look at CalcLogicalSubnet() in th UDF library. Using this UDF makes it easy and call kix script based on subnet. Even if you have a segment mask out as 255.255.255.128. You can get both logical subnets quickly.
|
|
Top
|
|
|
|
#19178 - 2002-03-28 06:43 PM
Re: Using Select/Case and OR
|
Anonymous
Anonymous
Unregistered
|
Thank you all for excellent examples (and syntax correction). As always, I can count on this board!!!.
|
|
Top
|
|
|
|
#19179 - 2002-03-28 07:13 PM
Re: Using Select/Case and OR
|
Anonymous
Anonymous
Unregistered
|
Well I have been experimenting some more with some of the suggestions in this thread this morning, and again THANKS! This stuff is really good.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 874 anonymous users online.
|
|
|