Tcpping.pl: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 36: | Line 36: | ||
</pre> | </pre> | ||
[[Category: | [[Category:Script]] |
Latest revision as of 14:18, 10 July 2020
#!/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; }