-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.php
More file actions
36 lines (29 loc) · 1007 Bytes
/
ping.php
File metadata and controls
36 lines (29 loc) · 1007 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
<?php
echo "<title>ping test</title>";
//simple php code to test if a server is responding to ping requests
// a ping test
function do_ping($host, $fping, $p_result) {
$fping = exec("ping $host -c1 -w2 | awk '/time/ {print $8}' | head -1 | awk -F '=' '{print $2}'");
if ($fping >= "0") {
echo "<font face=Verdana>Latency to host <b>$host</b> is <b>$fping ms.</b><br/></font>";
} else if ($fping == "") {
echo "<font face=Verdana>Host <b>$host</b> is not responding to ping.<br/></font>";
//you may add scripts here to trigger an sms email etc
}
}
do_ping("ns1.domainnamerecord.com", $fping, $p_result);
// in case you want to check a webserver i.e port 80
$server = "kashipur.net";
$port = "80";
$timeout = "10";
if ($server and $port and $timeout) {
$verbinding = @fsockopen("$server", $port, $errno, $errstr, $timeout);
}
if($verbinding) {
echo "$server is online";
}
else {
echo "$server 80 is offline";
//you may add scripts here to trigger an sms email etc
}
?>