-
Notifications
You must be signed in to change notification settings - Fork 27
/
nmapxml.php
73 lines (63 loc) · 2.34 KB
/
nmapxml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Parse NMAP XML output
*
* @version 20100303
* @author Koen Van Impe <koen.vanimpe@cudeso.be>
* @license New BSD : http://www.vanimpe.eu/license
*
*/
?>
<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>