#!/usr/local/bin/perl
# (C) Copyrght 1998 M. Dodge Mumford, All rights... Ah, hell, just use it.
# $Header: /home/dodge/cvs/www.dmumford.com/htdocs/tech/netmask.pl,v 1.1 2002/05/19 02:51:17 dodge Exp $
# $Name:  $

$| = 1 ;
$batches = 4 ;

print "<table border=1>\n" ;
for ( $currentbatch = 0; $currentbatch < $batches; $currentbatch++ ) {
	$newbatch = 1 ;
	for ( $netbits = 23; $netbits <= 30; $netbits++ ) {
		if ( $newbatch ) {
			print "<tr><td>.</td></tr><tr align=center>\n" ;
			print "<td></td><td></td><td></td>"
		} else {
			$netmask = 256 - 2 **(32-$netbits) ;
			print "<tr align=center>\n" ;
			print "<td>$netbits</td><td>$netmask</td><td></td>" ;
		}
		for ( $ip = 0 + $currentbatch * 256 / $batches;
			$ip < 0 + ($currentbatch+1) * 256 / $batches; $ip++ ) {
			if ( $newbatch ) {
				print "<td>$ip</td>" ;
			} else {
				print &cell ;
			}
		}
		print "\n" ;
		print "</tr>\n" ;
		$newbatch = 0 ;
	}
}
print "</table>\n" ;

sub cell {
	if ( $ip / (256 - $netmask) == int ( $ip / (256 - $netmask) ) ) {
		return "<td bgcolor=green>net</td>" ;
	} else {
		if ( ($ip+1) / (256-$netmask) == 
			int ( ($ip+1) / (256 - $netmask) ) ) {
			return "<td bgcolor=red>bcst</td>" ;
		} else {
			return "<td></td>" ;
		}
	}
	return 0 ; 
}
