#!/usr/bin/perl # Asgard Labs, 2004 (C) thorolf # this small hack can be used to get netmask for # network and number of hosts # # $ ./hostCount2NetMask.pl 192.168.1.0 255 # 192.168.1.0/24 # 192.168.1.0-192.168.1.255 # $ ./hostCount2NetMask.pl 10.10.2.96 31 # 10.10.2.96/27 # 10.10.2.96-10.10.2.127 # # enjoy use Net::Netmask; $siec=$ARGV[0]; $host=$ARGV[1]; $mask = sprintf("%d",32-(log($host)/log(2))); $block = new Net::Netmask ("$siec/$mask"); print $block->first() ."/$mask\n"; print $block->first() ."-" . $block->last() . "\n";