-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingrate
More file actions
executable file
·51 lines (43 loc) · 823 Bytes
/
Copy pathpingrate
File metadata and controls
executable file
·51 lines (43 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use Net::Ping;
if ($#ARGV == 0) {
$host = $ARGV[0];
} else {
print "Usage: pingrate <host>\n";
exit();
}
$p = Net::Ping->new("icmp");
$p->hires();
sub beep {
system("playsound --volume 0.2 /home/aparicio/scripts/beep.wav >/dev/null");
}
sub flat {
system("playsound --volume 0.1 /home/aparicio/scripts/flat.wav >/dev/null");
}
$fail = 0;
while (1) {
($ret, $time, $ip) = $p->ping($host, 2);
open(OUT, ">/tmp/router_status");
if ($ret) {
printf "%.2f ms from $ip\n", $time*1000, $ip;
printf OUT "%.2f ms\n", $time*1000;
if ($fail > 1) {
beep(); beep();
}
if ($fail > 0) {
$fail = 0;
}
} else {
printf "unreachable\n";
print OUT "unreachable\n";
if ($fail <= 2) {
beep();
} elsif ($fail == 3) {
flat();
}
$fail++;
}
close(OUT);
sleep(2);
}
$p->close();