Bernd Schemmer writes:
> I'm looking for a method to calculate the network address if I only have the
> IP address and the subnet mask from within a shell script.
>
> Maybe someone already wrote a function to do this
This works:
/usr/bin/perl -e '
use Socket;
$addr = inet_aton($ARGV[0]);
$mask = inet_aton($ARGV[1]);
$subnet = unpack("L", $addr) & unpack("L", $mask);
print inet_ntoa(pack("L", $subnet)), "\n";
' $ADDRESS $SUBNET
--
James Carlson, KISS Network <[EMAIL PROTECTED]>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
_______________________________________________
networking-discuss mailing list
[email protected]