Port checker with info from MySQL database


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. function statusCheck() {
  2. global $MySQLi;
  3. $query = "SELECT * FROM status_ports WHERE hidden = '0'";
  4. $commit = $MySQLi->query($query);
  5. if($commit == false) {
  6. trigger_error("Could not retrieve port listings.");
  7. }
  8. else
  9. {
  10. $report = array();
  11. $svcs = array();
  12. $hosts = array();
  13. while($row = $commit->fetch_assoc()) {
  14. $svcs[$row['name']] = $row['port'];
  15. $hosts[$row['name']] = $row['host'];
  16. }
  17. foreach ($svcs as $service=>$port) {
  18. $report[$service] = $this->check_port($hosts[$service], $port);
  19. }
  20. return $report;
  21. }
  22. }
  23.  
  24. function check_port($host = '', $port = '') {
  25. $conn = @fsockopen($host, $port, $errno, $errstr, 2);
  26. if ($conn) {
  27. fclose($conn);
  28. return true;
  29. }
  30. else
  31. {
  32. return "0";
  33. }
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.