Page 5 of 5 <12345
Topic Options
#101753 - 2003-06-06 10:50 AM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
also, now as you renamed some of the variables, for convenience and speed their place should be changed back to what they were.

example, $cidrarray and $point (dot) should be defined at the very beginning if used with their own separate variable-names.
_________________________
!

download KiXnet

Top
#101754 - 2003-06-06 11:02 AM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh...
I might ask for reviewing of:
code:
 $dum=Split($SubnetMask+$point+$NetworkID,$point)

hoby and all.
this was just for golf-score and the score does not go so much up if devided "properly".
as the code already does many compromises, this could be added to them.
_________________________
!

download KiXnet

Top
#101755 - 2003-06-06 11:43 AM Re: KIXgolf: MOAN(), Part II
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Thnx for the input,

Changed code a little, to make it more readable. The in the Golf reusing variables takes the char count down, but for "normal operation" re using variables may be confusing. Therefore adding some variables...

Will rename $dum, $point and $h.

Please clarify:
quote:
example, $cidrarray and $point (dot) should be defined at the very beginning if used with their own separate variable-names.
Updated code:
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=14;t=000748;p=3#000074
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#101756 - 2003-06-06 03:56 PM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
code:
;****************************************************************************
;
;SCRIPT/FUNCTION : MOAN()
;
;ACTION : Depending on the input, returns IP-addresses, Subnets,
; NetworkIDs or Yes-/No-is_in_subnet
;
;AUTHOR : Jooel Nieminen and Howard Bullock
;
;CONTRIBUTORS : Patrick Rutten (MightyR1@hotmail.com)
; - making the code readable
;
;VERSION : 1.0
; - 2003-06-05 Initial Release
;
;SYNTAX : MOAN($IP, $NetworkID, $SubnetMask)
;
;PARAMETERS :
;
;RETURNS : Input: IP, NetworkID, SubnetMask
; Output: 1 If the IP is a member of a network defined
; by NetworkID AND SubnetMask, otherwise 0
;
; Input: IP, NetworkID
; Output: Array of all potential SubnetMasks
; (CIDR notation) OR empty string If no match
;
; Input: IP, SubnetMask
; Output: NetworkID OR empty string If no match
;
; Input: NetworkID, SubnetMask
; Output: Array of all potential IP addresses OR
; empty string If no match
;
;REMARKS : This UDF is a result of a KiXGolf Tournament hosted by
; Sealeopard. Follow the links below to see how the game
; was played.
;
; Assumption: Network/broadcast addresses are NOT
; available as regular IP addresses though RFC3021
; allows /31 networks (two IP addresses where the
; network/broadcast addresses are used as regular
; IP addresses)
;
; At least two input parameters must be provided.
;
; If the output consists of an array of IP addresses,
; then the IP addresses must be sorted In ascending order.
;
; The subnet mask $SubnetMask can be either the traditional
; four-octets OR the alternate CIDR number,
; e.g. 255.255.255.0 AND 24.
;
; The parameters can contain up to two spaces between the
; decimal points AND the number, e.g. 192.168.0.10 AND
; 192.168. 0. 10 should be treated the same.
;
;DEPENDENCIES :
;
;EXAMPLE(S) :
; [Example 1]
; IP=192.168.1.2
; NetworkID=192.168.1.0
; SubnetMask=255.255.255.0
; MOAN=1
;
; [Example 2]
; IP=192.168.0.1
; NetworkID=192.168.1.0
; SubnetMask=255.255.255.0
; MOAN=0
;
; [Example 3]
; IP=
; NetworkID=10.10.5.4
; SubnetMask=255.255.255.252
; MOAN=10.10.5.5,10.10.5.6
;
; [Example 4]
; IP=192.10.128.55
; NetworkID=
; SubnetMask=27
; MOAN=192.10.128.32
;
; [Example 5]
; IP=10.10.10.2
; NetworkID=
; SubnetMask=255.255.255.254
; MOAN=
;
; [Example 6]
; IP=10.10.10.2
; NetworkID=10.10.10.0
; SubnetMask=
; MOAN=/23,/24,/25,/26,/27,/28,/29,/30
;
; [Example 7]
; IP=192.168.99.55
; NetworkID=192.168.99.55
; SubnetMask=
; MOAN=
;
;KNOWN ISSUES :
;
;KIXTART VER : 4.2x
;
;KIXTART BBS : KiXGolf: MOAN(), Mother Of All Networks -->
; - http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=14;t=000720
;
; KixGolf: MOAN(), Part II -->
; - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=14;t=000748
;
;****************************************************************************
;
;!
Function MOAN($IP,$NetworkID,$SubnetMask)

;declaring variables
Dim $cidrarray,$dot,$dummy,$subnetarray,$count,$help,$maskarray[3],$count2
Dim $first,$second,$third,$fourth

$cidrarray=0,128,192,224,240,248,252,254
$dot="."

;build SubnetMask; starting from bit 8 through 31
For $count=8 to 31

$dummy=$count
$help=1

;determine each octet
For $count2=0 to 3


;if bitnumber/8 > 0, the octet is 255 else the mod must be determined
;255.255.248.0=11111111.11111111.11111000.00000000
$maskarray[$count2]=IIf($dummy/8,255,$cidrarray[$dummy mod 8])

;8 must be substracted if one "moves" to the next octed
$dummy=($dummy>8)*($dummy-8)

;& the IP, NetworkID and the SubnetMask octets to see if the are "compatible"
If $IP & $NetworkID
$help=$help & Split($NetworkID,$dot)[$count2]=(0+Split($IP,$dot)[$count2] & $maskarray[$count2])
EndIf
Next

;if all variables are "compatible", add the bit number to the subnet string in CIDR notation
If $help
$subnetMask=$SubnetMask+" /"+$count
EndIf

;if current bit=current subnetmask then convert the SubnetMask to
;normal notation, e.g. 255.255.248.0
If $count=$SubnetMask
$SubnetMask=Join($maskarray,$dot)
EndIf

Next
;end Built subnet mask

$MOAN=$SubnetMask

;if the SubnetMask contains a point, calculate IP-addresses, NetworkIDs
;or Yes-/No-is_in_subnet
If InStr($SubnetMask,$dot)

$dummy=Split($SubnetMask+$dot+$NetworkID,$dot)
$MOAN=""

;if IP is provided, determine NetworkIDs
If $IP

;calculate the NetworkID
For $count=0 to 3
$MOAN=$MOAN+$dot+(0+$dummy[$count] & 0+Split($IP,$dot)[$count])
Next

;if IP=NetworkID there is no subnet, thus returning empty
If $dot+Join(Split($IP),"")=$MOAN
$MOAN=""
EndIf

;if NetworkID is provided:
; - return .0 if the calculated NetworkID <> provided NetworkID,
; IP is not in subnet
; - return .1 if the calculated NetworkID = provided NetworkID
; IP is in subnet
If $NetworkID
$MOAN=$dot+Join(Split($NetworkID),"")=$MOAN
EndIf

;determine array of IP numbers
Else

;first octet
For $first=$dummy[4] to 255 + $dummy[4] - $dummy[0]

;second octet
For $second=$dummy[5] to 255 + $dummy[5] - $dummy[1]

;Third octet
For $third=$dummy[6] to 255 + $dummy[6] - $dummy[2]

;Fourth octet
For $fourth=1+$dummy[7] to 254 + $dummy[7] - $dummy[3]

$MOAN = $MOAN+" "+$first+$dot+$second+$dot+$third+$dot+$fourth
Next

Next

Next

Next

EndIf

EndIf

;return the result
$dummy=$MOAN,Split(SubStr($MOAN,2))
$MOAN=$dummy[Len($MOAN)>1]

EndFunction
;!
;!
; end MOAN

this I mean.
for proper explanation see the difference between the winning code and the previous ones.
it's actually too messy with the comments to see where what looping do but looking the golf-codes you see immediately the difference [Wink]

will explain properly, if you still can't see it [Razz]
_________________________
!

download KiXnet

Top
#101757 - 2003-06-06 11:18 PM Re: KIXgolf: MOAN(), Part II
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
I see now, but how does this speed things up...

Why does KiX run faster if these lines are moved to the top???
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#101758 - 2003-06-07 01:07 AM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
as they are defined once.
in the previous one they were defined again in each loop. [Wink]
_________________________
!

download KiXnet

Top
#101759 - 2003-06-07 04:29 AM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
once again, I think some of the golf-codes should be posted as it is.
in the remarks we could write see next post for further examination of the code.

I don't see by any means any udf as teaching lab as they are not starters guides! they are UDFs!
they have input and they output what they are supposed to output.
none of even the coders need to understand what it does once it does what it's supposed to do!

thus, I don't see any reason for this re-write.

I think this pat's re-write could make a good standing point for referencing topic about the udf or supplementery post after the actual udf.

once again, UDF <> starters code clinic

and they never should be made "="!
_________________________
!

download KiXnet

Top
#101760 - 2003-06-07 05:41 AM Re: KIXgolf: MOAN(), Part II
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
WOW!! I think I have to agree with Lonkero on that point. [Eek!]
Top
#101761 - 2003-06-10 07:35 AM Re: KIXgolf: MOAN(), Part II
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
OK...

Then Jooel/Howard, make it a UDF and please refer to this topic for explanation [Wink]

Chris,

hope my comments are helpful...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#101762 - 2003-06-10 07:56 AM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
pat, maybe...
it might serve good as it was with real semi-coding explanation of what is happening.

this way the comments doesn't have to be so long and they surely will be understandable.
and when they are not inside the code itself, it's easier to follow the code and the explanation...
_________________________
!

download KiXnet

Top
#101763 - 2003-06-10 02:04 PM Re: KIXgolf: MOAN(), Part II
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Pat, definitely helpful.

Lonk,
quote:

UDF <> starters code clinic

and they never should be made "="!

...but KiXGolf <> UDF forum either. While <> Starters forum either, I thought that the purpose was to advance KiX scripting methods. It'd be a shame for the brilliant coding that was done to be lost on the majority because no one understands what went on. At any rate, this is my last post on the subject.

Top
#101764 - 2003-06-10 03:36 PM Re: KIXgolf: MOAN(), Part II
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
chris, sure.
that was not my argument...

and I bet you understood it too.
we were discussing about posting the udf in udf forum.
I don't stand against code explanations.
just inline comments in udf-forum [Razz]
well... that is argumentary also, but anyway.
I indeed see the point of making things clearer for more ppl to benefit.

specially all the tricks should be explained.
_________________________
!

download KiXnet

Top
#101765 - 2003-06-17 04:04 AM Re: KIXgolf: MOAN(), Part II
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
A KiXGolf UDF can definitely be posted in the UDF forum. However, if you want ot put comments into the KiXGolf UDF, then you should not change the UDF code. KiXGolf UDFs are on the more compact side and thus use some KiXtart features that normal UDF do not use. Thus, the UDF comments should reflect these intricacies.
_________________________
There are two types of vessels, submarines and targets.

Top
#101766 - 2003-06-17 10:36 AM Re: KIXgolf: MOAN(), Part II
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
True,

but then I ask Jooel/Howard to write usefull comments in the winning code and post here...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#101767 - 2003-06-20 03:07 PM Re: KIXgolf: MOAN(), Part II
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Just wanted to let you guys know that all of your hard work on this UDF has not been in vain. [Wink] I'm going to use MOAN() to help move Computer objects in our AD to their proper OU based off of their IP address. I've really just started on the script, that is to say that I've got the logic framework down, but so far it's working like a champ. [Smile]
Top
#101768 - 2003-06-20 05:50 PM Re: KIXgolf: MOAN(), Part II
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Just so you're aware of the limitations of MOAN(), but it might have a slight problem with Class-A networks under certain conditions.

[ 20. June 2003, 17:56: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#101769 - 2003-06-20 06:32 PM Re: KIXgolf: MOAN(), Part II
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Thanks for the info, Jens. We're not using Class A so we should be OK in this instance.
Top
Page 5 of 5 <12345


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

Who's Online
0 registered and 208 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.027 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