print "Subnet Reference Guide -- http://www.netadmintools.com\n\n"; # I will place comments under calculations to explain where the numbers come from. # Also, I will add tricks to remember table creations. As much as possible, # I try to use generation techniques that stem from the way the tables work. # If you understand the program, then not only can you generate the table if needed, # like before a TCP/IP test :-), but you will also understand how subnetting # actually works mathematically. It is silly to use rules like, "take the column # to the left, double it, and add 2. for($i=0;$i<8;$i++){ $bit[$i]=2**$i; } # Assign bit[0] to bit[7] with decimal values (2^X = 2**X) Bit 0 is on right. print "Value of individual bits in an eight bit byte if true:\n\n"; for($i=7;$i>=0;$i--){ print "Bit ", $i," = ",$bit[$i],"\n"; } print "\nClass 1st Octet start (binary) Decimal Range\n"; print "A 0 ", 0*$bit[7]+1,"-", $bit[7]-2, "\n"; # all 0s and all 1s invalid network/host ids, 127 reserved for loopback # bit[7]-1=sum(bit[0]..bit[6]) This is the same idea as 1000-1=999. I will use this lots. print "B 10 ", $bit[7],"-",$bit[7]+$bit[6]-1,"\n"; print "C 110 ", $bit[7]+$bit[6],"-",$bit[7]+$bit[6]+$bit[5]-1,"\n\n"; #Ok, 0 is universe (void), add one person (Adam), add another one (Eve), all IP's come from this. # Add on left: A,B,C. If you can't prove it, get mystical! printf "\n%10s %10s %10s %10s %10s %10s","Subnet","Block","Max", "#C IPs/","#B IPs/","#A IPs/ \n"; printf "%10s %10s %10s %10s %10s %10s","Mask","Size","Subnets", "Subnet","Subnet","Subnet\n"; printf "---------------------------------------------------------------------\n"; $subnet_mask=$bit[7]; for($i=6;$i>=0;$i--){ # the bit split to start is 2 for network, 6 for host. We finish at 8 network, 0 host. $subnet_mask=$subnet_mask+$bit[$i]; #This gives us the decimal value of all ones in the octet for the current network bit split. #Remember that the subnet mask is all ones over the network portion the of the octet because #a logical AND is used to separate network and host portions. $number_subnets=2**(8-$i)-2; # Sum of true bits for network portion -2 for all 1s and all 0s $block_size=$bit[$i]; # Remember this is a bit split loop, so $i is one more than bit location number. if($i>1){ $cnum=$bit[$i]-2; # -2 since all 1s and all 0s invalid } else{ $cnum=0; } $bnum=2**(8+$i)-2; $anum=2**(16+$i)-2; printf "%10d %10d %10d",$subnet_mask, $block_size, $number_subnets; printf "%10d %10d %10d\n", $cnum, $bnum, $anum; } print "\n Valid Block Chart\n"; print "------------------------------------------\n"; printf "%10s %10s %10s", "Size 16","Size 32","Size 64\n"; print "------------------------------------------\n"; for ($i=1;$i<=2;$i++){ printf " %3d-%3d %3d-%3d %3d-%3d\n",$i*16+1,$i*16+14,$i*32+1,$i*32+30,$i*64+1,$i*64+62; } for ($i=3;$i<=6;$i++){ printf " %3d-%3d %3d-%3d\n",$i*16+1,$i*16+14,$i*32+1,$i*32+30; } for ($i=7;$i<=14;$i++){ printf " %3d-%3d \n",$i*16+1,$i*16+14; }