noccylabs/net

$ git tag
0.1.0

$ git branch
* master

Network Tools for PHP

This library currently supports ping (with callbacks on responses), and traceroute. As each class is intended to only do the bare essentials, the traceroute class will not ping the hosts but only resolve the path.

Examples

These examples are stripped down. Please see the examples directory in the source tree for current info.

IpAddress

$network = new IpAddress("192.168.0.0");
$mask = new IpAddress("0.0.0.255");

$test1 = new IpAddress("192.168.0.5");
$test2 = new IpAddress("192.168.1.5");

$test1->isInNetwork($network, $mask); // true
$test2->isInNetwork($network, $mask); // false

IpRange

$range = new IpRange("192.168.0.0/24");
foreach ($range as $ip) {
    // ...
}

Ping

$p = new Ping("192.168.0.10");
$p->run(function ($r) {
    if (!$r->isSuccess()) {
        printf(
            "Warning: got error '%s' from %s when pinging %s\n", 
            $r->getStatus(), 
            $r->getHost(), 
            $r->getTarget()
        );
    } else {
        printf("Response from %s: %.2f ms\n", $r->getTarget(), $r->getMs());
    }
}, 10);

Traceroute

$trace = new TraceRoute("github.com");
$trace->run();
foreach ($trace as $hop=>$ip) {
    // ...
}