Advertisement
H4T3D

Check Which Ports Are Open ?

Sep 2nd, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. set_time_limit(0);
  4. $host = 'stackoverflow.com';
  5. $ports =
  6. array(
  7. 1,
  8. 5,
  9. 7,
  10. 18,
  11. 20,
  12. 21,
  13. 22,
  14. 23,
  15. 25,
  16. 29,
  17. 37,
  18. 42,
  19. 43,
  20. 49,
  21. 53,
  22. 69,
  23. 70,
  24. 79,
  25. 80,
  26. 103,
  27. 108,
  28. 109,
  29. 110,
  30. 115,
  31. 118,
  32. 119,
  33. 137,
  34. 139,
  35. 143,
  36. 150,
  37. 156,
  38. 161,
  39. 179,
  40. 190,
  41. 194,
  42. 197,
  43. 389,
  44. 396,
  45. 443,
  46. 444,
  47. 445,
  48. 458,
  49. 546,
  50. 547,
  51. 563,
  52. 569,
  53. 1080
  54. );
  55.  
  56. foreach ($ports as $port)
  57. {
  58.    $fp=fsockopen($host, $port);
  59.  
  60.     if ($fp)
  61.     {
  62.         echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";
  63.     fclose($fp);
  64.     flush();@ob_flush();
  65.     }
  66.  
  67.     else
  68.     {
  69.         echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
  70.     fclose($fp);
  71.     flush();@ob_flush();
  72.     }
  73. }
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement