#!/usr/bin/perl -w use strict; use warnings; use IO::Socket; use Time::Stopwatch; $| = 1; my $first = 3; my $last = 0; if (my $arg_first = shift) { if ($arg_first =~ /^\d+$/) { $first = $arg_first; } } if (my $arg_last = shift) { if ($arg_last =~ /^\d+$/) { $last = $arg_last; } } printf "\nfirst : %d\nlast : %d\n\n", $first, $last; my %results; while (my $server = ) { chomp $server; tie my $timer, 'Time::Stopwatch'; my $sock = IO::Socket::INET->new ( Proto => 'tcp', PeerAddr => $server, PeerPort => 21, ); if ($sock) { close $sock; $results{$timer} = $server; printf "%-25s%-10sOK\n", $server, sprintf("%.3fs", $timer); } else { printf "%-25s%-10s%s\n", $server, sprintf("%.3fs", $timer), $!; } untie $timer; } unless (%results) { print "\n"; exit; } print "\n\nPlace Time Server\n\n"; my $i = 0; my @top = sort keys %results; my $count = $#top; foreach my $time (@top[0 .. $first - 1]) { next unless defined $time; printf "%-8s%-10s%s\n", sprintf("%3s", ++$i), sprintf("%.3fs", $time), $results{$time}; } if ($last > 0) { print "\n...\n\n"; $i = $#top - $last + 2; foreach my $time (@top[$#top - $last + 1 .. $#top]) { next unless defined $time; printf "%-8s%-10s%s\n", sprintf("%3s", $i++), sprintf("%.3fs", $time), $results{$time}; } } print "\n";