Skip to content

Instantly share code, notes, and snippets.

@hcooper
Created February 8, 2011 15:24
Show Gist options
  • Save hcooper/816573 to your computer and use it in GitHub Desktop.
Save hcooper/816573 to your computer and use it in GitHub Desktop.
Script to ping tcp connections, which gets round firewall ICMP blocks. Taken from the Backuppc mailing list here: http://www.mail-archive.com/[email protected]/msg07903.html
#!/usr/bin/perl -w
use strict;
use Net::Ping;
die "usage: $0 port hostname\n" unless(@ARGV == 2);
my $serv = shift @ARGV;
my $host = shift @ARGV;
my $p = Net::Ping->new("tcp", 30);
$p->hires();
if($serv =~ /^\d+/) {
$p->{port_num} = $serv;
} else {
$p->{port_num} = getservbyname($serv, "tcp");
}
my @res = $p->ping($host);
if(@res) {
my ($succ,$rtt,$ip) = @res;
if($succ) {
my $ms = int ($rtt*1000);
print "$host [$ip] - $serv - time=$ms ms\n";
} else {
exit -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment