I know there was already solution posted, just wrote my own ver of it.

print "Enter the IP address: ";
$ip = <>;
print "Enter the Subnet address: ";
$sn = <>;

chomp $ip; chomp $sn;
$ip=CIDR2bin($ip);
$sn=CIDR2bin($sn);
printf "The network adr is: %vd\n", $ip & $sn;


sub CIDR2bin{  return pack 'c4',split /\./, shift; }


----- Original Message -----
From: "Kipp, James" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 27, 2002 11:31 AM
Subject: RE: ANDing IP addresses


> > > I want to bitwize AND 2 IP adr strings, not sure of how to
> > pack() them to be
> > > able to AND them. before i start playing with
> > pack,sprintf,socket,etc.. I
> > > was wondering if someone already had a way.
> >
> > $ perl -e 'printf "%vd\n", 192.168.1.1 & 255.255.0.0'
> > 192.168.0.0
> >
>
> quoting the string in anyway seems to break it. i am trying to read in the
> strings from <STDIN> like this:
> print "Enter the IP address: ";
> $ip = <STDIN>;
> print "Enter the Subnet address: ";
> $sn = <STDIN>;
>
> printf "The network adr is: %vd\n", $ip & $sn;
> --
> output:
> Enter the IP address: 192.168.1.1
> 192.168.1.1
>
> Enter the Subnet address: 255.255.255.0
> 255.255.255.0
>
> The network adr is: 48.49.48.46.48.52.48.46.48.36.49.10
> ---
>
> how can i make this work ?
>
> Thanks
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to