Hi Bill, Thanks. I have subnet mask in dotted decimal notation - which I have to convert into Hex format. I need code to convert from dotted decimal to Hex and Hex to dotted decimal notation.
Rao -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of $Bill Luebkert Sent: Monday, June 14, 2004 9:04 PM To: [EMAIL PROTECTED] Subject: Re: bitwise AND operation on IP addr and subnet mask in perl Anthony Nemmer wrote: > Be careful though, since perl doesn't have unsigned 32 bit integers, > some IP addies might be large enough to flip the high bit on, > don't know if this would be a problem or not.... Changed first segment to 255 (255.168.0.1): ip=4289200129 (ffa80001), mask=4294901760 (ffff0000), net 4289200128 (ffa80000) seems ok. Notice I'm using unsigned format to print. > $Bill Luebkert wrote: > > >>Viswanatha Rao wrote: >> >> >> >> >>>Hello, >>> >>> >>> >>>I have to perform a bitwise AND operation on an IP address and a subnet >>>mask, to generate a network number and host ID. Can anyone tell me how >>>to do this? >>> >>> >> >>Try something like: >> >>use strict; >> >>my @ip = split /\./, '192.168.0.1'; >> >>my $ip = 0; >>$ip = ($ip << 8) | $_ foreach @ip; >> >>my $mask = 0xffff0000; >>my $net = $ip & $mask; >> >>printf "ip=%u (%08x), mask=%u (%08x), net %u (%08x)\n", $ip, $ip, $mask, $mask, >> $net, $net; >> >>__END__ >> -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
