Page 1 of 1 1
Topic Options
#19172 - 2002-03-27 05:54 PM Using Select/Case and OR
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
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
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 Offline
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
#19176 - 2002-03-27 07:34 PM Re: Using Select/Case and OR
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You can also look into using the SUBNET() and ISINSUBNET() UDFs to differentiate IP addresses based on subnet masks.
_________________________
There are two types of vessels, submarines and targets.

Top
#19177 - 2002-03-27 08:33 PM Re: Using Select/Case and OR
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#19178 - 2002-03-28 06:43 PM Re: Using Select/Case and OR
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
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
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 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.079 seconds in which 0.06 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