in reply to convert longIP to stringIP

Aah - yes - I've run into this before.
The Database returns signed 32-bit integers. The high IP addresses show up as negative integers.

I would recommend using a module to handle IP addresses - my favourite is NetAddr::IP which works admirably but it won't solve your problem - you need a little more magic..

Your problem can be solved using this :

$n = get_number_from_database(); my $ip = NetAddr::IP->new($n < 0 ? 2**32 + $n : $n); # $ip now contain and IP object which can be printed , # or converted to binary, or checked for # subnet membership.
(Thanks to Luis E. Muņoz, author of NetAddr::IP, for the original tip)

Replies are listed 'Best First'.
Re: Re: convert longIP to stringIP
by fokat (Deacon) on Sep 14, 2003 at 14:50 UTC

    Thanks NetWallah. I was about to post the tip myself ;)

    I'll be adding this to ->new as soon as I get the time...

    Best regards

    -lem, but some call me fokat