#!/usr/bin/perl use Net::Netmask; #$FS = '\t'; #$, = ' '; $\ = "\n"; use Getopt::Long; &GetOptions ("ip=s", "mask=s", "checkip=s", "help"); $ERRFLAG = 0; if ( $opt_help == 1 ) { &usage; exit 0; } if ( !$opt_ip ) { print "option '--ip=aaa.bbb.ccc.ddd' is obligatory"; $ERRFLAG = 1; } if ( !$opt_mask ) { print "option '--mask=aaa.bbb.ccc.ddd | --mask=0xaabbccdd' is obligatory"; $ERRFLAG = 1; } if ( $ERRFLAG ) { &usage; exit 1; } $block = new Net::Netmask ($opt_ip, $opt_mask); print "a.b.c.d/bits .... ", $block->desc(); print "netaddress ...... ", $block->base(); print "netmask ......... ", $block->mask(); print "broadcast ....... ", $block->broadcast(); print "hostmask ........ ", $block->hostmask(); #print "subnet-bits ..... ", $block->bits(); print "blocksize ....... ", $block->size(); print "hostaddresses ... ", $block->nth(1), " - ", $block->nth(-2); print "next net ........ ", $block->next(); if ( $opt_checkip ) { print "\nchecked host .... ", $block->match($opt_checkip), "\nif 'checked host' = 0 then hostip doesn't match this network"; } sub usage { print "\nusage: $0 [--help] --ip=ip-address --mask=netmask [--checkip=ip-address]\n"; print " ip-address aaa.bbb.ccc.ddd (decimal)"; print " netmask aaa.bbb.ccc.ddd | 0xaabbccdd (hexadecimal)\n"; print " checkip aaa.bbb.ccc.ddd (decimal)"; print "examples: $0 --ip=192.168.210.196 --mask=255.255.255.192"; print " $0 --ip=192.168.210.196 --mask=0xffffffc0"; print " $0 --ip=192.168.210.192 --mask=255.255.255.192 --checkip=192.168.210.196"; }