我没有获得此PHP程序的输出

时间:2015-03-18 03:01:47

标签: php pear nmap

虽然我包含了所有文件,但我没有得到输出

<?php

    /**
     * Scan network to retrieve hosts and services information.
     */

    require_once 'C:/xampp/php/pear/Net/Nmap.php';

    //Define the target to scan
    $target = array('127.0.0.1','localhost');

    $options = array('nmap_binary' => 'C:/Program Files (x86)/Nmap');

    try {
        $nmap = new Net_Nmap($options);

        //Enable nmap options
        $nmap_options = array('os_detection' => true,
                              'service_info' => true,
                              'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',//to scan only specified ports
                              );

        $nmap->enableOptions($nmap_options);

        //Scan target
        $res = $nmap->scan($target);

        //Get failed hosts
        $failed_to_resolve = $nmap->getFailedToResolveHosts();

        if (count($failed_to_resolve) > 0) {
            echo 'Failed to resolve given hostname/IP: ' .
                 implode (', ', $failed_to_resolve) .
                 "\n";
        }

        //Parse XML Output to retrieve Hosts Object
        $hosts = $nmap->parseXMLOutput();

        //Print results
        foreach ($hosts as $key => $host) {
            echo 'Hostname: ' . $host->getHostname() . "\n";
            echo 'Address: ' . $host->getAddress() . "\n";
            echo 'OS: ' . $host->getOS() . "\n";
            echo 'Status: ' . $host->getStatus . "\n";
            $services = $host->getServices();
            echo 'Number of discovered services: ' . count($services) . "\n";
            foreach ($services as $key => $service) {
                echo "\n";
                echo 'Service Name: ' . $service->name . "\n";
                echo 'Port: ' . $service->port . "\n";
                echo 'Protocol: ' . $service->protocol . "\n";
                echo 'Product information: ' . $service->product . "\n";
                echo 'Product version: ' . $service->version . "\n";
                echo 'Product additional info: ' . $service->extrainfo . "\n";
            }
        }
    } catch (Net_Nmap_Exception $ne) {
        echo $ne->getMessage();
    }
    ?>

1 个答案:

答案 0 :(得分:0)

如果您的程序没有任何输出,则表示您有语法错误,致命错误或段错误。

使用E_ALL更改php.ini设置,启用,dispaly_errors和error_reporting 通常,这就足够了。您可以看到错误消息并修复错误。

如果仍然没有错误消息,请尝试创建一个简单文件,仅显示phpinfo()。 如果这样可以,通常,你没有启动错误,如果没有,请在php.ini中启用display_startup_errors

如果你仍然没有错误,请检查你的apache或nginx configure,你可能错误地配置了网站。

如果你还没有错误,恭喜!你有段错误。 使用gdb找到原因。