Created
February 8, 2011 15:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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