You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use Term::ANSIColor;
|
|
|
|
|
|
|
|
if ($ARGV[0] !~ /[a-z0-9\.]+/) {
|
|
|
|
print "Need... Arg...\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dns=$ARGV[0];
|
|
|
|
|
|
|
|
if ($^O == "linux") {
|
|
|
|
$regex=qr/(?<bytes>[0-9]+ bytes) from (?<rhost>[a-z\.-]+) \((?<rip>[0-9\.]+)\).*seq=(?<rseq>[0-9]+).*time=(?<rms>[0-9\.]+) ms/;
|
|
|
|
$dedjex=qr/no answer yet for icmp_seq=(?<rseq>[0-9]+)/
|
|
|
|
$pingcmd="ping -O"
|
|
|
|
} elsif ($^O == "MSWin32") {
|
|
|
|
# untested lol
|
|
|
|
$regex=qr/Reply from (?<rip>[0-9\.]+).*bytes time=(?<rms>[0-9\.]+)ms.*/;
|
|
|
|
$dedjex=qr/Request timed out|Destination host unreachable/
|
|
|
|
$pingcmd="ping -t"
|
|
|
|
} else {
|
|
|
|
print "IDK WHAT OS YOU ARE :(";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
open(my $PING, "$pingcmd $dns|") or die "Cannot execute $!";
|
|
|
|
|
|
|
|
while (my $line = <$PING>) {
|
|
|
|
if ($line =~ $regex) {
|
|
|
|
if ($+{rms} > 100) {print color("bright_red");}
|
|
|
|
elsif ($+{rms} > 50) {print color("bright_yellow");}
|
|
|
|
printf "% 3s - % 4s ms - %s (%s)\n", $+{rseq}, $+{rms}, $+{rhost}, $+{rip};
|
|
|
|
if ($+{rms} > 50) {print color("reset");}
|
|
|
|
} elsif ($line =~ $dedjex) {
|
|
|
|
print color("bright_red");
|
|
|
|
printf "% 3s - no reply %s\n", $+{rseq}, $dns;
|
|
|
|
print color("reset");
|
|
|
|
} else {
|
|
|
|
print $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close($PING);
|
|
|
|
|