#101756 - 2003-06-06 03:56 PM
Re: KIXgolf: MOAN(), Part II
|
Lonkero
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
will explain properly, if you still can't see it
_________________________
!download KiXnet
|
Top
|
|
|
|
#101760 - 2003-06-07 05:41 AM
Re: KIXgolf: MOAN(), Part II
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
WOW!! I think I have to agree with Lonkero on that point.
|
Top
|
|
|
|
#101763 - 2003-06-10 02:04 PM
Re: KIXgolf: MOAN(), Part II
|
Chris S.
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
|
|
|
|
#101767 - 2003-06-20 03:07 PM
Re: KIXgolf: MOAN(), Part II
|
Chris S.
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. 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.
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 208 anonymous users online.
|
|
|