Skip to content

Instantly share code, notes, and snippets.

@Dviros
Last active July 23, 2019 22:33
Show Gist options
  • Save Dviros/8bda16bc71844fac7dca0d052098ffbe to your computer and use it in GitHub Desktop.
Save Dviros/8bda16bc71844fac7dca0d052098ffbe to your computer and use it in GitHub Desktop.
Simple and effective NMAP parser using PowerShell
$file = read-host "Full path for NMAP scan XML file, eg C:\nmap.xml"
$xml = [xml](Get-Content $file)
$Results = $Xml.nmaprun.host |
ForEach-Object {
$hash = [ordered]@{}; $hash.Address = $_.address.addr
Foreach ($port in $_.ports.port) {
$hash."$($port.service.name)" = $port.state.state
}
[PSCustomObject]$hash
}
write-host "Services found:" $hash.keys.Count
write-host "Services names:" $hash.keys
$service_selected = read-host "which service do you want to check? type it's name, eg microsoft-ds. Can use multiple services, comma seperated"
$state_selected = read-host "which state do you want to check? filtered, open, closed, tcpwrapped"
$Results | Select-Object address,$service_selected | Where-Object $service_selected -EQ $state_selected | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment