Skip to content

Instantly share code, notes, and snippets.

@ibejohn818
Created April 29, 2014 20:32
Show Gist options
  • Save ibejohn818/375c56562b9a018a38f2 to your computer and use it in GitHub Desktop.
Save ibejohn818/375c56562b9a018a38f2 to your computer and use it in GitHub Desktop.
Nmap Quick and Dirty
<?php
class Nmap {
public function __contruct() {
}
public function ssh_query_network($user,$host,$ip_cidr,$sudo = true,$tmpPath = "/tmp") {
$file = str_replace("/","-",$ip_cidr).".xml";
$login = "ssh -t {$user}@{$host} ";
$cmd = "nmap -sP -oX {$tmpPath}/$file {$ip_cidr};";
if($sudo) {
$cmd = "sudo {$cmd}";
}
// passthru("{$login} '{$cmd}'",$res);
exec("{$login} '{$cmd}'",$out,$res);
$this->parseXmlNetworkQuery("{$tmpPath}/{$file}");
}
private function parseXmlNetworkQuery($xml) {
$xml = simplexml_load_file($xml);
foreach($xml->host as $host) {
echo "################################","\n";
echo "Status:","\n";
echo "------ State: ".$host->status->attributes()->state,"\n";
echo "------ Reason: ".$host->status->attributes()->reason,"\n";
foreach($host->address as $k=>$address) {
echo "Address {$k}:","\n";
echo "------ Type {$k}: ".$address->attributes()->addrtype,"\n";
echo "------ Addr {$k}: ".$address->attributes()->addr,"\n";
}
echo "Hostname:","\n";
echo "------ Addr {$k}: ".$host->hostnames->hostname->attributes()->name,"\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment