mojobo has asked for the wisdom of the Perl Monks concerning the following question:
now i'm trying to get the broadcast address, but i'm having some problems converting the 1's complement of the subnet mask back to something readable..perl -e '$ip="192.168.10.2"; $mask="255.255.254.0"; @maskbyte=split /\ +./,$mask; @ipbyte=split /\./, $ip; for($i=0;$i<4;$i++) { $b1=$maskbyt +e[$i]+0; $b2=$ipbyte[$i]+0;$NetByte=$b1&$b2; if($i != 0) {$NetAddr = +$NetAddr . "." . $NetByte; } else { $NetAddr=$NetByte ;}} print "$Net +Addr\n";'
the one's complement of the subnet mask orred with the network address (formula for broadcast) gives a funky number..perl -e '$ip="192.168.10.0"; $mask="255.255.254.0"; @maskbyte=split /\ +./,$mask; @ipbyte=split /\./, $ip; for($i=0;$i<4;$i++) { $b1=$maskbyt +e[$i]+0; $b2=$ipbyte[$i]+0; $NetByte=$b2 || ~$b1 ; if($i != 0) {$Ne +tAddr = $NetAddr . "." . $NetByte; }else { $NetAddr=$NetByte ;}} prin +t "$NetAddr\n";'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl ipcalc oneliners
by Fletch (Bishop) on Jun 09, 2005 at 23:56 UTC | |
|
Re: perl ipcalc oneliners
by monarch (Priest) on Jun 09, 2005 at 23:55 UTC |