Archive für 16.7.2007

tcp_echo

even the echo service is disabled on Linux machines, it’s nevertheless an easy way to figure out spurios network delays. TIn perl the basics are already written in the NET::PING module. I only added some timing to it. If you don’t have the perl modules installed, a workaround is creating a script containing the line

echo $2 | /usr/bin/netcat -v $1 7

which you could than invoke with time scriptname host.domain.dmn string_to_use
here ist the other way

#!/usr/bin/perl
# simple tcp echo programm
# sample usage (verbose mode)
# /xxx/bin/tcp_echo.pl -v 1 -h host.domain.dmn
# /xxx/bin/tcp_echo.pl: host.domain.dmn 2
# res = 1 host host.domain.dmn time: 0.012088
# sample usage (normal mode)
# /root/bin/tcp_echo.pl -h host.domain.dmn
# res = 1 host host.domain.dmn time: 0.010903
#
use strict;
use Getopt::Long;
use Net::Ping;
use Time::HiRes;
use Time::HiRes qw(gettimeofday tv_interval);

my $program_name = $0;
my $timeout = 2;
my $hostname = “localhost”;
my $debug = 0;

sub helpMessage()
{
print “$program_name [-h|-?] [-v #] [-t #] [-h FQDM] [\n”;
print “-help|? this message\n”;
print “-v[erbose] enables debug messages \n”;
print “-t[imeout] timeout (default: 2)\n”;
print “-h[ost] hostname FQDN (default: localhost) \n”;
exit 1;
}

sub run()
{
my $t0 = [gettimeofday];
my $res = pingecho( $hostname, $timeout );
my $t1 = [gettimeofday];
my $elapsed = tv_interval $t0, $t1;
print “res = $res host $hostname time: $elapsed\n”;
}

Getopt::Long::Configure (”bundling”);
my $l_result = GetOptions (
‘help|?’ => sub { helpMessage() },
‘verbose|v=n’ => \$debug,,
‘host|h=s’ => \$hostname,
‘timeout|t=n’ => \$timeout);

print “$program_name: $hostname $timeout \n” if $debug;

&run();

|