Tcpping.pl: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(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 "...) |
No edit summary |
||
Line 1: | Line 1: | ||
<pre> | <pre> |
Revision as of 13:23, 16 January 2009
#!/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; }