Code Monkey home page Code Monkey logo

portscan-async's Introduction

Asynchronous port scanner in PHP

This package offers a portscan utility to determine if a host is reachable on a certain (TCP) port or not.

Scenario

A status page has to report if certain hosts are online. Using the normal methods, each host will be checked sequentially, which is slow. Thanks to this class, all of the checks are performed asynchronously, and the status of all hosts can be checked in a non-blocking way.

Functions

  • setTimeout($float) : timeout for all checks to terminate
  • addTest($host, $port) : add a host to test
  • scan() : start scan
  • results : variable that holds the results

Example

$ss = new PortScan\Scanner;
$ss->setTimeout(2);

$ss->addTest('yahoo.com', 80);
$ss->addTest('google.com', 80);
$ss->addTest('1.2.3.4', 80);

$ss->scan();
var_dump($ss->results);
Result
array(3) {
  ["google.com"]=>
  array(1) {
    [80]=>     ## Holds the port
    int(0)     ## Holds the error number (0 = port open)
  }
  ["yahoo.com"]=>
  array(1) {
    [80]=>
    int(0)
  }
  ["1.2.3.4"]=>
  array(1) {
    [80]=>
    int(10060)
  }
}

For an overview of error numbers, look here.


Future
  • callbacks per test/globally
  • UDP scan (although I'm not sure how to do this reliably)
Keywords

multi threaded port scan status check checker scanner open closed non-blocking

portscan-async's People

Contributors

c3c avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.