portless-easy-ping
Code (php)
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
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
<?php
$ip = $_GET['ip']; //$ip kan 127.0.0.1 of google.be zijn
$timeout = 200;
if(status($ip,$timeout)){
echo "$ip is up";
}else{
echo "$ip is down";
}
function status($ip,$timeout) {
ob_start();
system('ping '.$ip." -n 1 -w ".$timeout."ms");
$out = ob_get_contents();
ob_end_clean();
if(preg_match_all('{Packets:(.+?),(.+?),(.+?),(.+?)}',$out,$all)) {
$ex = explode("=",$all[2][0]); //$all[2][0] = "Received = 1" (of 0)
if($ex[1] == '1') {
return true;
} else {
return false;
}
}
}
?>
$ip = $_GET['ip']; //$ip kan 127.0.0.1 of google.be zijn
$timeout = 200;
if(status($ip,$timeout)){
echo "$ip is up";
}else{
echo "$ip is down";
}
function status($ip,$timeout) {
ob_start();
system('ping '.$ip." -n 1 -w ".$timeout."ms");
$out = ob_get_contents();
ob_end_clean();
if(preg_match_all('{Packets:(.+?),(.+?),(.+?),(.+?)}',$out,$all)) {
$ex = explode("=",$all[2][0]); //$all[2][0] = "Received = 1" (of 0)
if($ex[1] == '1') {
return true;
} else {
return false;
}
}
}
?>