示例#1
0
<?php

require_once 'userio.php';
require_once 'ipv6calc.php';
function is_cli()
{
    return php_sapi_name() === 'cli';
}
function load_io_interface($is_cli)
{
    return $is_cli ? new CommandLineIo() : new WebIo();
}
$io = load_io_interface(is_cli());
try {
    $input = $io->read_input();
    $ipv6calc = IPv6Calculator::load($input);
    $io->write_output($ipv6calc);
} catch (Exception $e) {
    $io->write_error($e->getMessage());
}
示例#2
0
        }
        $diff = $t - $c;
        $newSegments = array();
        foreach ($segments as $i => $segment) {
            if (empty($segment)) {
                for ($i = 0; $i <= $diff; $i++) {
                    $newSegments[] = '0000';
                }
                continue;
            }
            $newSegments[] = $segment;
        }
        if (count($newSegments) !== 8) {
            throw new \Exception('Expanding segments failed for unknown reason');
        }
        $segments = $newSegments;
        unset($newSegments);
        return $segments;
    }
}
// lets run this thing
$calc = new IPv6Calculator();
if (isset($_REQUEST['cidr'])) {
    if ($calc->calc($_REQUEST['cidr']) === true) {
        var_dump($calc->getNetworkRange());
    } else {
        echo $calc->getErrorMessages();
    }
} else {
    echo "No Request received";
}