mojobo has asked for the wisdom of the Perl Monks concerning the following question:
hi all, i'm building some fun perl one-liners for use with external programs and such.. i found a cool perl script that i converted to a single-liner that computes the network address of a unix machine:
this computes the network address..
here's what i have so far:
192.168.10.4294967295
this computes the network address..
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";'
here's what i have so far:
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";'
192.168.10.4294967295
Back to
Seekers of Perl Wisdom