Takes an IP address and turns it into the corresponding decimal.
$ip ='192.168.2.1'; $dec = unpack('N32',pack("C4", split(/\./,$ip))); print "IP:$ip equals $dec\n";

Replies are listed 'Best First'.
Re: Turn an IP into a decimal number
by jmcnamara (Monsignor) on Apr 10, 2002 at 14:26 UTC

    Nice, but you only need to use one big-endian long 'N':     my $dec = unpack 'N', pack "C*", split /\./, $ip;

    Here's a example for the curious: http://3519380377/.

    --
    John.