Petite Abeille wrote:

On Nov 23, 2011, at 4:24 AM, Arvind wrote:

To do this I want to convert an IP address of the form A.B.C.D into a
number that will serve as an index of the array.

Well, IP4 addresses can simply be represented as a decimal.

So, 127.0.0.1 is 2130706433.

Or as a four byte string:

$ perl -MSocket -le'my $x = inet_aton( "127.0.0.1" ); print "\177\0\0\1" eq $x ? "true" : "false"'
true


Example on how to calculate it:

http://www.allredroster.com/iptodec.htm

Or in Perl:

$ perl -MSocket -le'my $x = inet_aton( "127.0.0.1" ); print unpack "N", $x'
2130706433


IP6 addresses are a different kettle of fish:

Agreed.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to