<?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;
			}
		}
	}
?>