Created
April 29, 2014 20:32
-
-
Save ibejohn818/375c56562b9a018a38f2 to your computer and use it in GitHub Desktop.
Nmap Quick and Dirty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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