#!/usr/bin/perl -T use strict; use warnings; $|=1; # ipaddr2int.pl - convert IPv4 addresses from stdin to integers on stdout # $Id: ipaddr2int.pl,v 1.1 2009/10/01 13:46:20 jtk Exp $ while ( defined(my $line=<>) ) { chomp $line; next if $line !~ m{ \A \d{1,3} (?: [.] \d{1,3}){3} \Z }xms; my @bytes = split /\./, $line; my $int = unpack( "N", pack("C4", @bytes) ); print "$int\n"; }