BassemZammeli
BassemZammeli

Reputation: 1

Error using PHP PEAR XAMPP 7.0.2.1 Net_Nmap

I'm trying the PEAR Net_Nmap package from here:
https://pear.php.net/package/Net_Nmap/

I have Nmap installed on my Windows 10 machine. I found the following code that should do the job. Is there something I should configure before I use PEAR?

I'm getting 2 errors:

Warning: require_once(XML/Parser.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\Parser.php on line 31

Fatal error: require_once(): Failed opening required 'XML/Parser.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\Parser.php on line 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();
}
?>

Upvotes: 0

Views: 945

Answers (1)

cweiske
cweiske

Reputation: 31137

You did not use the PEAR installer to install the net_nmap package, but probably downloaded the .tgz file and extracted it.

Now you are missing the dependencies which are listed on the bottom left of the Net_NMap page. Install them.

Upvotes: 0

Related Questions