Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. // Posted at http://www.w3tools.info/2011/12/simple-port-scanner-php.html
  3. require("header.php");
  4.  
  5. $host = $_POST['host'];
  6. $start = $_POST['start'];
  7. $end = $_POST['end'];
  8. $proto = $_POST['protocol'];
  9. $serv = $_POST['services'];
  10.  
  11. ?>
  12.  
  13.  
  14.  
  15.  
  16.  
  17. <html>
  18. <body>
  19. <div class="box">
  20. <h2>Port Scanner</h2>
  21. <div class="box-content">
  22. <center>
  23. <p><form name='scanner' method='post' action='<?php echo $PHP_SELF; ?>'>
  24. Host name or IP:
  25. <input type='text' name='host' value='<?php echo $host; ?>' /><br/>Starting Port: <input type='text' name='start' value='<?php echo $start; ?>' /><br/>Ending Port: <input type='text' name='end' value='<?php echo $end; ?>' /><br/>Protocol: <select name='protocol'>
  26. <option value='tcp'>tcp</option>
  27. <option value='udp'>udp</option>
  28. </select>
  29. <br/>Show services: <input name='services' type='checkbox' value='yes' /><br/><input type='submit' value='Scan Ports' />
  30. <br /><br />
  31. </center>
  32.  
  33. </div>
  34. </div>
  35.  
  36. <div class="box">
  37. <h2>Results:</h2>
  38. <div class="box-content">
  39. <center>
  40. <?php
  41.  
  42. if(isset($host) && isset($start) && isset($end) && isset($proto))
  43. {
  44. echo "<strong></strong><br />";
  45.  
  46. for($current = $start; $current <= $end; $current++)
  47. {
  48. if($serv == "yes")
  49. {
  50. $service = getservbyport($current, $proto);
  51. }
  52.  
  53. $result = fsockopen($host, $current, $errno, $errstr, 1);
  54.  
  55. if($serv == "yes")
  56. {
  57. echo "Port: <strong>".$current."</strong> is commonly used for: <strong>".$service."</strong> and was ";
  58. }
  59. else
  60. {
  61. echo "Port: <strong>".$current."</strong> was ";
  62. }
  63. if($result)
  64. {
  65. echo "<font color='green'><strong>OPEN</strong></font><br />";
  66. }
  67.  
  68. else
  69. {
  70. echo "<font color='red'><strong>CLOSED</strong></font><br />";
  71. }
  72.  
  73. }
  74. }
  75. ?>
  76. </center>
  77. </div>
  78. </div>
  79.  
  80. <?php
  81. include 'footer.php';
  82. ?>