Tcpping.pl

From Federal Burro of Information
Revision as of 13:23, 16 January 2009 by David (talk | contribs) (New page: A more generic smtpping.pl] <pre> #!/usr/bin/perl -w use strict; use Net::Ping; if (defined($ARGV[1])){ } else { print "Error: wrong number of arguments.\n"; print "...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

A more generic smtpping.pl]

#!/usr/bin/perl -w

use strict;
use Net::Ping;

if (defined($ARGV[1])){
} else {
        print "Error: wrong number of arguments.\n";
        print "Usage: $0 host port\n";
        exit 1;
}

if ( $ARGV[1] =~ /^\d+$/ ){
} else {
        print "Error: bad port\n";
        print "Usage: $0 host port\n";
        exit 1;
}

if (defined($ARGV[0])){
        my $p = Net::Ping->new("tcp", 2);
        # $p->{port_num} = getservbyname($ARGV[1], "tcp");
        # print "Protocol is ".getservbyport($ARGV[1], "tcp" )."\n";
        $p->{port_num} = $ARGV[1];
        # older versions of Net::Ping dont do this
        # FIXME detect version of Net::Ping module UNIVERSAL -> can (method )
        # $p->service_check( 1 );
        exit 1 unless $p->ping($ARGV[0])
} else {
        print "Error: wrong number of arguments.\n";
        print "Usage: $0 host port\n";
        exit 1;
}