【问题标题】:Error using PHP PEAR XAMPP 7.0.2.1 Net_Nmap使用 PHP PEAR XAMPP 7.0.2.1 Net_Nmap 时出错
【发布时间】:2016-06-14 19:44:30
【问题描述】:

我正在从这里尝试 PEAR Net_Nmap 包:
https://pear.php.net/package/Net_Nmap/

我在我的 Windows 10 机器上安装了 Nmap。 我发现下面的代码应该可以完成这项工作。 在使用 PEAR 之前有什么需要配置的吗?

我收到 2 个错误:

警告:require_once(XML/Parser.php):无法打开流:第 31 行的 C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\Parser.php 中没有这样的文件或目录

致命错误:require_once():在 C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\ 中打开所需的 'XML/Parser.php' (include_path='C:\xampp\php\PEAR') 失败Parser.php 在第 31 行

<?php
// Scan network to retrieve hosts and services information.
require_once 'Net/Nmap.php';

//Define the target and options
$target = array('193.95.13.16','www.google.com');
$options = array('nmap_binary' => 'C:\Program Files (x86)\Nmap');

try {
    $nmap = new Net_Nmap($options);
    $nmap_options = array(
        'os_detection' => true,
        'service_info' => true,
        'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080', 
    // Only           specified    ports
    );
    $nmap->enableOptions($nmap_options);

    // Scan
    $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();
}
?>

【问题讨论】:

标签: php apache xampp pear nmap


【解决方案1】:

您没有使用PEAR installer安装net_nmap package,但可能下载了.tgz文件并解压。

现在您缺少 Net_NMap 页面左下方列出的依赖项。安装它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 2023-02-10
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    相关资源
    最近更新 更多