Created
June 5, 2014 09:25
-
-
Save Tjoosten/1d787d4b4b38a6d0626a to your computer and use it in GitHub Desktop.
Simple portscanner in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" > | |
Domain/IP: | |
<input type="text" name="domain" /> | |
<input type="submit" value="Scan" /> | |
</form> | |
<br /> | |
<?php | |
if(!empty($_POST['domain'])) { | |
//list of port numbers to scan | |
$ports = array(21, 22, 23, 25, 53, 80, 110, 1433, 3306); | |
/* | |
| Port numbers: | |
| ----------------------- | |
| Port 21 = FTP | | |
| Port 22 = SSH | | |
| Port 23 = Telnet | | |
| Port 25 = SMTP | | |
| Port 53 = Domain | | |
| Port 80 = HTTP | | |
| Port 110 = POP3 | | |
| Port 1433 = ms-sql-s | | |
| Port 3306 = MySQL | | |
| ----------------------- | |
*/ | |
$results = array(); | |
foreach($ports as $port) { | |
if($pf = @fsockopen($_POST['domain'], $port, $err, $err_string, 1)) { | |
$results[$port] = true; | |
fclose($pf); | |
} else { | |
$results[$port] = false; | |
} | |
} | |
foreach($results as $port=>$val) { | |
$prot = getservbyport($port,"tcp"); | |
echo "Port $port ($prot): "; | |
if($val) { | |
echo "<span style=\"color:green\">OK</span><br/>"; | |
} | |
else { | |
echo "<span style=\"color:red\">Inaccessible</span><br/>"; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment