#101735 - 2003-06-04 10:49 PM
Re: KIXgolf: MOAN(), Part II
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Good job Lonkero.
Some of the feeling this outing caused?
thanks Jens. [ 04. June 2003, 22:50: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#101740 - 2003-06-05 09:22 AM
Re: KIXgolf: MOAN(), Part II
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
|
Top
|
|
|
|
#101743 - 2003-06-05 06:22 PM
Re: KIXgolf: MOAN(), Part II
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Chris, I don't have much time now. Is there something or some part of the program that you would like a quick recap?
At the moment I on a phone connection in a Microsoft sales office so I do not know how long I will remain connected until this evening. [ 05. June 2003, 18:23: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#101747 - 2003-06-05 11:53 PM
Re: KIXgolf: MOAN(), Part II
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
Chris, here ye go...
I added some variables to make things more clear. This version passes the tests with a score of 1184
Jooel, Howard,
please verify my comments and if necessary modify the comments. If all is OK, then it will be posted as a UDF.
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 ;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 $cidrarray=0,128,192,224,240,248,252,254 ;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]) $dot="." ;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
{2003-06-06-11:45 changed after Jooel's suggestions} [ 06. June 2003, 11:38: Message edited by: MightyR1 ]
_________________________
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 566 anonymous users online.
|
|
|