-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseNmap.ps1
More file actions
58 lines (53 loc) · 1.77 KB
/
ParseNmap.ps1
File metadata and controls
58 lines (53 loc) · 1.77 KB
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
# ################################################ #
# ################################################ #
# #
# Currently this script does not work as intended #
# The objective is to parse an nmap XML file #
# and recover a list of hosts or IP addresses #
# for processing in other applications #
# #
# ################################################ #
# ################################################ #
# Check a file has been passed
param([string]$path="")
if ($path -eq "") {
Write-Host "Missing Path"
Exit
}
[xml]$holder = Get-Content $path
$block = $holder.nmaprun
# Powershell arrays are annoying
# Enumerate total number of ports open
$a = $holder.nmaprun.host.ports.port | Measure-Object -Line | Select -ExpandProperty Lines
$role = New-Object string[] $a
$c = 0
foreach ($obj in $block) {
$ips = $holder.nmaprun.host.ipaddr | Select -ExpandProperty Addr
$hostname = $block.host.hostnames.hostname | Select -ExpandProperty Name
$portz = $block.host.ports
foreach ($t in $portz) {
$box = $t.port
$cat = $t.port | Select -ExpandProperty portid
$stat = $t.port | Select -ExpandProperty state
foreach ($b in $box) {
if ($b -eq "445") {
$role[$c] = "Probable Windows - Port 445 in use"
}
else {
if ($b -eq "22") {
$role[$c] = "Nix or Networking - Port 22 in use"
}
else {
$role[$c] = "Unknown"
}
}
}
$c = $c + 1
}
}
$c = 0
foreach ($a in $ips) {
# Error Check
Write-Host $ips[$c] " - " $role[$c]
$c = $c + 1
}