Page 1 of 1 1
Topic Options
#41985 - 2003-06-23 07:36 PM Subnet/Sub-subnet detection question
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Running into a bit of a snag here. Hope this is not too lame, but I am going cross-eyed. [Big Grin]

Running the following test code -
code:
cls
break on
$1st=ltrim(split(@ipaddress0,'.')[0])
$2nd=ltrim(split(@ipaddress0,'.')[1])
$3rd=ltrim(split(@ipaddress0,'.')[2])
$4th=ltrim(split(@ipaddress0,'.')[3])
$ipadr='$1ST.$2ND.$3RD.$4TH'
SELECT
CASE
$2nd=13
MIGRATE
SCRIPT
CASE
$2nd=53 OR $2nd=110 OR $2nd=38 OR $2nd=126
GOTO SCRIPT
CASE
$2nd=50
$subnetname=Split('0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 23 195')
FOR EACH $element IN $subnetname
?$element
IF $element=$3rd
MIGRATE
SCRIPT
ELSE
SCRIPT
ENDIF
NEXT
;CASE 1
; GOTO SCRIPT
ENDSELECT
get $
?"Stop here"

FUNCTION MIGRATE()
?"MIGRATE"
get $
ENDFUNCTION

FUNCTION SCRIPT()
?"SCRIPT"
ENDFUNCTION

get $

So.. What is going on? If I am at the 195 sub-subnet, it wants to run all of the others first. What I really need is to evaluate the whole array and then go on.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#41986 - 2003-06-23 07:49 PM Re: Subnet/Sub-subnet detection question
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Think it would evaluate SCRIPT for all those where $2nd is 50 and $rd not 195, and SCRIPT & MIGRATE for $2nd=50 and $3rd = 195 ... at least thats the way it reads ... think we (i anyways) might need more words around whats wrong or where your trying to get to.

-Shawn

[ 23. June 2003, 19:52: Message edited by: Shawn ]

Top
#41987 - 2003-06-23 07:49 PM Re: Subnet/Sub-subnet detection question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
At first glance...
Your code returns $2nd as a string but your case is looking for integer.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#41988 - 2003-06-23 07:54 PM Re: Subnet/Sub-subnet detection question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You could either convert to integer:

$2nd=Val(split(@ipaddress0,'.')[1])

or use quotes in your case statements:

CASE
 $2nd='50'
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#41989 - 2003-06-23 07:57 PM Re: Subnet/Sub-subnet detection question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
and vars in strings... tsk! tsk!

$ipadr='$1ST.$2ND.$3RD.$4TH'

$ipadr=''+$1ST+'.'+$2ND+'.'+$3RD+'.'+$4TH
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#41990 - 2003-06-23 08:04 PM Re: Subnet/Sub-subnet detection question
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Here is the code and works fine. Thanks for the suggestions and setting me straight.

Note: The uncommented and commented out code.
code:
cls
break on
$1st=ltrim(split(@ipaddress0,'.')[0])
$2nd=ltrim(split(@ipaddress0,'.')[1])
$3rd=ltrim(split(@ipaddress0,'.')[2])
$4th=ltrim(split(@ipaddress0,'.')[3])
$ipadr=''+$1ST+'.'+$2ND+'.'+$3RD+'.'+$4TH
SELECT
CASE
$2nd='13'
MIGRATE
SCRIPT
CASE
$2nd='53' OR $2nd='110' OR $2nd='38' OR $2nd='126'
GOTO SCRIPT
CASE
$2nd='50'
$subnetname=Split('0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 23 195')
FOR EACH $element IN $subnetname
?$element
IF $3rd=$element
MIGRATE
SCRIPT
;ELSE
; SCRIPT
ENDIF
NEXT
CASE 1
GOTO SCRIPT
ENDSELECT
get $
?"Stop here"

FUNCTION MIGRATE()
?"MIGRATE"
get $
ENDFUNCTION

FUNCTION SCRIPT()
?"SCRIPT"
ENDFUNCTION

get $

Thanks,

Kent

[ 25. June 2003, 16:59: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#41991 - 2003-06-23 08:23 PM Re: Subnet/Sub-subnet detection question
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why not use the IsInSubnet() UDF for this?

BTW, I will post a completely rewritten IsInSubnet() UDF either tonight or tomorrow morning that will not require any dependencies and can evaluate whether an IP address is part of any or all subnets that are provided to the UDF.
_________________________
There are two types of vessels, submarines and targets.

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.066 seconds in which 0.036 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