Check if a program is running on UDP port

Various / CUSTOM BUILT
June 4, 2016 at 05:00:33
Specs: Windows 10.0.10586 Pro, Intel i7 4770k, 32GB 1600MHz RAM
I'm working on a web page, and I am hosting quite a few servers, some are TCP and some are UDP. I'd like to make them appear as online/offline on the page. I managed to make it work for TCP using
<?php
	function ConnectTCP($PORT) {
		$serverConn = @stream_socket_client("tcp://127.0.0.1:$PORT", $errno, $errstr, 1);
		if ($errstr != '') {
			return false;
		}
		fclose($serverConn);
		return true;
	}
?>

However this doesn't work with UDP, as it is connectionless.
I tried this, but it only returns a bunch of warnings and doesn't actually work

<?php
	function ConnectUDP($PORT) {
		$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
		socket_bind($socket, "127.0.0.1", $PORT);
		socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>1,"usec"=>0));
		socket_recvfrom($socket, $buf, 12, MSG_OOB, $from, $PORT);
		if ($buf != '') {
			socket_close($socket);
			fclose($socket);
			return true;
		}
		socket_close($socket);
		fclose($socket);
		return false;
	}
?>

Is there a way to accomplish the same as with TCP, either using PHP, or some other language that is intagratable with HTML?

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


See More: Check if a program is running on UDP port

Report •


#1
November 7, 2016 at 06:35:43
What doing this function? function ConnectUDP($PORT) {
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, "127.0.0.1", $PORT);
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>1,"usec"=>0));
socket_recvfrom($socket, $buf, 12, MSG_OOB, $from, $PORT);
if ($buf != '') {
socket_close($socket);
fclose($socket);
return true;
}
socket_close($socket);
fclose($socket);
return false;
}
?>

Report •

#2
November 10, 2016 at 04:17:11
It's my failed attempt at trying to detect if a given UDP port is open. You can disregard it completely.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •
Related Solutions


Ask Question