예제 #1
0
//script can only be run from cli
if (php_sapi_name() != "cli") {
    die(json_encode(array("status" => 1, "error" => "This script can only be run from cli!")));
}
//check input parameters
if (!isset($argv[1]) || !isset($argv[2])) {
    die(json_encode(array("status" => 1, "error" => "Missing required input parameters")));
}
// test to see if threading is available
if (!Thread::available()) {
    die(json_encode(array("status" => 1, "error" => "Threading is required for scanning subnets. Please recompile PHP with pcntl extension")));
}
/**
 *	Create array of addresses to scan
 */
$scan_addresses = $Scan->prepare_addresses_to_scan("discovery", $argv[1]);
$z = 0;
//addresses array index
/*
test
*/
$ports = explode(";", $argv[2]);
$out = array();
//reset array, set each IP together with port
foreach ($scan_addresses as $k => $v) {
    foreach ($ports as $p) {
        $addresses[] = array("ip" => $v, "port" => $p);
    }
}
# run per MAX_THREADS
for ($m = 0; $m <= sizeof($addresses); $m += $Scan->settings->scanMaxThreads) {
예제 #2
0
if ($Scan->icmp_type == "fping") {
    if (!file_exists($Scan->settings->scanFPingPath)) {
        die("Invalid fping path!");
    }
}
//first fetch all subnets to be scanned
$scan_subnets = $Subnets->fetch_all_subnets_for_discoveryCheck(1);
//set addresses
if ($scan_subnets !== false) {
    // initial array
    $addresses_tmp = array();
    // loop
    foreach ($scan_subnets as $s) {
        // if subnet has slaves dont check it
        if ($Subnets->has_slaves($s->id) === false) {
            $addresses_tmp[$s->id] = $Scan->prepare_addresses_to_scan("discovery", $s->id, false);
        }
    }
    //reindex
    if (sizeof($addresses_tmp) > 0) {
        foreach ($addresses_tmp as $s_id => $a) {
            foreach ($a as $ip) {
                $addresses[] = array("subnetId" => $s_id, "ip_addr" => $ip);
            }
        }
    }
}
if ($Scan->debugging) {
    print_r($scan_subnets);
}
if ($scan_subnets === false) {
예제 #3
0
    }
    # parse result
    if (sizeof(@$Scan->fping_result) == 0) {
        die(json_encode(array("status" => 0, "values" => array("alive" => null))));
    } else {
        //check each line
        foreach ($Scan->fping_result as $l) {
            //split
            $field = array_filter(explode(" ", $l));
            //create result
            $out['alive'][] = $Subnets->transform_to_decimal($field[0]);
        }
    }
} else {
    # Create array of addresses to scan
    $scan_addresses = $Scan->prepare_addresses_to_scan($argv[1], $argv[2]);
    $z = 0;
    //addresses array index
    //run per MAX_THREADS
    for ($m = 0; $m <= sizeof($scan_addresses); $m += $Scan->settings->scanMaxThreads) {
        // create threads
        $threads = array();
        // fork processes
        for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= sizeof($scan_addresses); $i++) {
            //only if index exists!
            if (isset($scan_addresses[$z])) {
                //start new thread
                $threads[$z] = new Thread("ping_address");
                $threads[$z]->start($Subnets->transform_to_dotted($scan_addresses[$z], true));
                $z++;
                //next index