sub ipto32bit {
#
# Convert a dotted quad c.d.e.f to a single unsigned 32bit number.
#
my ($ip, $c, $d, $e, $f);
$ip = shift;
($c,$d,$e,$f) = split(/\./,$ip);
return ($c << 24) + ($d << 16) + ($e << 8) + $f;
}
####
#!/usr/bin/perl -wl
use strict;
chomp(my @ips = );
my @sorted_ips = sort by_ip(@ips);
print for (@sorted_ips);
sub by_ip {
return ipto32bit($a) <=> ipto32bit($b);
}
sub ipto32bit {
#
# Convert a dotted quad c.d.e.f to a single unsigned 32bit number.
#
my ($ip, $c, $d, $e, $f);
$ip = shift;
($c,$d,$e,$f) = split(/\./,$ip);
return ($c << 24) + ($d << 16) + ($e << 8) + $f;
}
__DATA__
12.345.111.3
12.345.111.26
61.8.47.111
12.345.111.24
203.134.35.27
12.345.111.5
12.345.111.4
####
12.345.111.3
12.345.111.4
12.345.111.5
12.345.111.24
12.345.111.26
61.8.47.111
203.134.35.27