code:
; begin MOAN
;
;!
Function moan($a,$b,$c)
Dim $,$e,$f,$g,$h,$m[32]

; Convert all input data to numeric array elements.
; The array is 12 elements each element is value (0-255).
;'$' hold the input data and later is the array version of the input data


;Build Subnet Mask ARARRY
$f=0,128,192,224,240,248,252,254,255
for $e=8 to 31
Dim $h
$=$e
for $g=1 to 4
$h=$h+iif($/8,"255",$f[$ mod 8])+iif($g<4,".","")
$=iif($>8,$-8,0)
next
$m[$e]=$h
next
;End build mask array


$h=$c
if $c
;Convert mask bits to 1.2.3.4 format
if len($c)<3
$c=$m[$c]
endif
; End convert bits
else
$c="..."
endif


;build array of input values by splitting a string. Then convert to integers
;IPaddr = $[0..3] NetID = $[4..7] Mask = $[8..11]
$="..."
$=split(IIF($a,$a,$)+"."+IIF($b,$b,$)+"."+$c,".")
for $e=0 to 11
$[$e]=0+$[$e]
next
;End build array


if $a and $h ;Output: Network ID or empty string if no match

;Calculate NetworkID using $ array
$e=""
for $c=0 to 3
$e=$e+"."+($[$c] & $[$c+8])
next
$=substr($e,2)

if join(split($a),"")=$
$=""
endif

;Output: 1 if the IP is a member of a nework defined by network ID and subnet mask, otherwise 0
;Input NetworkID = Calculated NetworkID
if $b
$=IIF(join(split($b),"")=$,1,0)
endif
else

;Output: Array of all potential subnet masks or empty string if no match
if $a and $b
$a=""
for $f=8 to 31
$b=1
for $e=0 to 3
$b=$b & $[$e+4]=($[$e] & 0+split($m[$f],".")[$e])
next
if $b
$a=$a+" /"+$f
endif
next

$=IIF($a,split(substr($a,2)),"")
else
;Output: Array of all potential IP addresses or empty string if no match
$a=""
for $b=$[4] to $[4] + 255 - $[8]
for $c=$[5] to $[5] + 255 - $[9]
for $e=$[6] to $[6] + 255 - $[10]
for $f=$[7]+1 to $[7] + 254 - $[11]
$a = $a+" "+$b+"."+$c+"."+$e+"."+$f
next
next
next
next
$=IIF($a,split(substr($a,2)),"")
endif
endif

$moan=$
EndFunction
;!
;!

; end MOAN

code:
KiXtart
KiXtart Version = 4.21
KiXGolf Script = kixgolf_moan.kix

Computer
OS = Windows 2000 Professional
CPU = Intel Pentium III
Speed = 848 MHz
Memory = 512 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: MOAN - Mother Of All Networks
Processing Start = 2003/05/30 15:30:53.505
Processing End = 2003/05/30 15:30:53.595
Duration = 0000/00/00 00:00:00.090
# Loops = 1
KiXGolf Result = passed (10 out of 10 correct)
KiXGolf Score = 836

Thank you for participating in KiXtart Golf!



[ 30. May 2003, 21:27: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/