I've got a script using PHP and fsockopen to check whether a port is open or closed. It is working some of the time but there are several ports on my IP address I know are open but its returning closed. Anyone have any advice?
<?php
$timeout = "10";
if ( isset($_GET['submit'] ) )
{
$server = ($_GET['server']);
$port = ($_GET['port']);
if ($server and $port and $timeout) {
$verbinding = @fsockopen("$server", $port, $timeout);
}
if($verbinding) {
echo "<mark>Port $port is open</mark><br>";
}
else {
echo "<mark>Timed Out: Port $port is closed.</mark><br>";
}
}
?>
The HTML
<form method="get" action="">
Server IP/URL:<input type="text" name="server" id="server" pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$" required><br>
Port Number:<input type="number" name="port" id="port" min="1" max="65535" required><br>
<input type="submit" name="submit">
</form>
Thanks in advance!