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
<?php

	$timeout = (isset($_GET['timeout']) ? ($_GET['timeout'] <= 0 ? 30 : ((int)$_GET['timeout'])) : 30);
	
	if(empty($_GET['ip'])&&empty($_GET['port'])){
		echo 'No IP/Port specified.';
	}
	else{
		$ch = curl_init();

		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		curl_setopt ($ch, CURLOPT_URL, $_GET['ip']);
		curl_setopt ($ch, CURLOPT_PORT , $_GET['port']);
		curl_setopt ($ch, CURLOPT_HEADER, 0);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

		$response = curl_exec ($ch);
		curl_close ($ch);
		
		if($response == true){
			echo 'online';
		}else{
			echo 'offline';
		}
	}

?>