Return to Snippet

Revision: 67735
at October 23, 2014 01:01 by LostNerd


Initial Code
function statusCheck() {
		global $MySQLi;
		$query = "SELECT * FROM status_ports WHERE hidden = '0'";
		$commit = $MySQLi->query($query);
		if($commit == false) {
			trigger_error("Could not retrieve port listings.");
		}
		else
		{
			$report = array();
			$svcs = array();
			$hosts = array();
			while($row = $commit->fetch_assoc()) {
				$svcs[$row['name']] = $row['port'];
				$hosts[$row['name']] = $row['host'];
			}
			foreach ($svcs as $service=>$port) {
				$report[$service] = $this->check_port($hosts[$service], $port);
			}
			return $report;
		}
	}
	
	function check_port($host = '', $port = '') {
		$conn = @fsockopen($host, $port, $errno, $errstr, 2);
		if ($conn) {
			fclose($conn);
			return true;
		}
		else
		{
			return "0";
		}
	}

Initial URL


Initial Description
Pulls info from the database to check if a specific port is open or service is online on a server.

Initial Title
Port checker with info from MySQL database

Initial Tags


Initial Language
PHP