note 26993 added to function.xml-parse-into-struct
| From: | joeldegan at yahoo dot com | Date: | Tue, 19 Nov 2002 22:40:01 +0000 |
| Subject: | note 26993 added to function.xml-parse-into-struct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39714@lists.php.net to get a copy of this message | ||
Using one of the nice function above, I was able to get these two great structures below on nmap
info for a machine and then the PID lists for each open port.. Very handy for my current project.
$test =
nmap -sU -sS localhost -oX -;
$ret = xml2array($test);
$z=0;
while (list($key,$val)=each($ret["host"][0][3]["children"])){
if ($val["tag"] == "PORT"){
$new[$z]["PROTOCOL"] = $val["attributes"]["PROTOCOL"];
$new[$z]["PORT"] = $val["attributes"]["PORTID"];
//echo $val["attributes"]["PROTOCOL"]."\n";
//echo $val["attributes"]["PORTID"]."\n";
$z++;
}//fi
}//wend
print_r($new);
function port_pids($portnum){
$ret = lsof -i :$portnum -F pc;
$ret = explode("\n", $ret);
$z=0;
for($a=0;$a<count($ret);$a++){
$port = $ret[$a];
$a++;
$com = $ret[$a];
$new[$z]["PID"]=substr($port, 1);
$new[$z]["COMMAND"]=substr($com, 1);
$z++;
}//wend
return $new;
}//end function
print_r(port_pids("3306"));
--
http://www.php.net/manual/en/function.xml-parse-into-struct.php
http://master.php.net/manage/user-notes.php?action=edit+26993
http://master.php.net/manage/user-notes.php?action=delete+26993
http://master.php.net/manage/user-notes.php?action=reject+26993