nmap XML to HTML parser
I was recently in need for a parser that would convert Nmap XML output to a HTML file. As far as I could see there was no tool available so I wrote my own. Feel free to use or adjust it.
<!--
Parse nmap XML output
Koen Van Impe cudeso.be
20100303
-->
<html>
<head><title>nmap xml file to html</title></head>
<body>
<form method="POST" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
XML file: <input type="file" name="xmlfile" <br />
<input type="checkbox" checked name="open"> Open <br />
<input type="checkbox" name="closed"> Closed <br />
<input type="checkbox" name="filtered"> Filtered <br />
<input type="submit" value="Press"> to upload the file!
</form>
<?php
if(isset($_FILES['xmlfile'])) {
// init
if (trim($_POST["open"]) == "on") $printOpen = true;
else $printOpen = false;
if (trim($_POST["closed"]) == "on") $printClosed = true;
else $printClosed = false;
if (trim($_POST["filtered"]) == "on") $printFiltered = true;
else $printFiltered = false;
$xmlObject = simplexml_load_file($_FILES['xmlfile']['tmp_name']);
// output the header
echo "<h1>".(string)$xmlObject["args"]."</h1>";
echo "<h2>Hosts up: ".(string) $xmlObject->runstats->hosts["up"]." / Hosts down: ".
(string) $xmlObject->runstats->hosts["down"]. " / Hosts total: ".(string) $xmlObject->runstats->hosts["total"]."</h2>";
// run through the xml and print hostinfo
foreach($xmlObject as $host => $value) {
// Only grab the data if it's host related info
if ((string) $host == "host") {
// declare portsarray
$nmap["ports"] = array();
// get the hostinfo
echo "<h2>".(string) $value->hostnames->hostname["name"].
" (".(string) $value->address["addr"]." / ".(string) $value->address["addrtype"].")</h2>";
echo "<table>";
// put the discovered ports in an array
foreach ($value->ports->port as $port) {
if ( ( ((string) $port->state["state"] == "filtered") and ($printFiltered)) or
( ((string) $port->state["state"] == "closed") and ($printClosed)) or
( ((string) $port->state["state"] == "open") and ($printOpen))
) {
echo "<tr><td>".(string)$port["portid"]."/".(string)$port["protocol"]."</td><td>".
(string)$port->state["state"]."(".(string)$port->state["reason"].")</td>
<td>".$port->service["name"]."(".(string)$port->service["product"].")
</tr>";
}
}
echo "</table>";
}
}
}
?>
</body>
</html>
Trackback by Graco Nautilus 3 In 1 Car Seat — May 5, 2010 @ 13:17
Graco Nautilus 3 In 1 Car Seat…
Nice post I’ve enjoyed studying it as well as I have refrred your post to my listing of related sites look it over http://www.graconautilus3in1carseats.com/tag/graco-nautilus-3-in-1-multiuse-car-seat-daisy/...
Trackback by free blog websites — May 5, 2010 @ 21:08
free blog websites…
Create content editor webpart (CEWP) paste the following java script code inside it. script type \”text/ javascript\” ( function (){ // creates scrollbar for web part with configured height var arrayList ( \”div[ id \'WebPartWPQ\']\” ). get…
Trackback by free blogspot backgrounds — June 3, 2010 @ 11:09
free blogspot backgrounds…
Let’ s say I’ m ranking Transformers number one for the sake of the peanut gallery. I can’ t really grasp the fascination with robots turning into cars and such myself, but the show seemed to captivate the imagination of little boys everywhere (and sel…
Comment by Christian — June 20, 2010 @ 00:42
Thanks Koen, this is a great tool. This will shave some time off of my own efforts to process nmap XML outputs.
Hey, and at least one human actually posting a comment should make you feed better after 3 spam posts
Cheers!