Skip to content

Latest commit

 

History

History
77 lines (64 loc) · 2.34 KB

2008-06-19-discovery-hosts-and-services-with-php-and-nmap.markdown

File metadata and controls

77 lines (64 loc) · 2.34 KB
layout title date categories comments
post
Discovery hosts and services with PHP and Nmap
2008-06-19 23:39:38 +0200
pear
php
nmap
true

Requirements:

{% codeblock lang:php %}

'/usr/local/bin/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(); } ?>

{% endcodeblock %}