Last active
June 7, 2016 15:20
-
-
Save mbrownnycnyc/a69345cd8f034192b9ba2947ab708470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #nmap -T4 -sV --allports -v 10.8.6.0/24 -oX nmap_10_8_6_0.xml | |
| $ipservicespairs = @{} | |
| C:\Users\user\Desktop\Parse-Nmap.ps1 "C:\Users\user\Desktop\nmap_10_8_6_0.xml" -outputdelim "@" | where { $_.status -ne "down" } ` | |
| | foreach-object { | |
| $ipservicespairs.add( $_.ipv4, ($_.services).split('@') ) | |
| } | |
| $csvoutput = New-Object System.Collections.Generic.List[object] | |
| #enumerate the ipservicepairs as declared above (note that the .split() caused a string[] (string array) to be generated) | |
| foreach ( $ipservicespair in $ipservicespairs.keys ) { | |
| $ipv4 = $ipservicespair #this is the key | |
| $services = $ipservicespairs.item($ipservicespair) #this is the value | |
| #since the value is a string[] (string array) | |
| # with the goal to create a CSV with column A being the IP and column B being a service | |
| # we must create another hashtable object (in the case $csvoutput) and store key-value pairs for each ipv4+service pair | |
| foreach ($service in $services) { | |
| $tempout = "" | select ipv4, serviceTransportProtocol, servicePortNumber, serviceProto, serviceDescription, serviceIDConfidenceLevel | |
| $tempout.ipv4 = $ipv4 | |
| #parse the service string into a service struct: | |
| #ex: $service = "tcp:8089:http:Splunkd httpd ssl <100%-confidence>" | |
| if ($service.length -gt 0 ) { | |
| $service = $service.split(':') | |
| $tempout.serviceTransportProtocol = $service[0] | |
| $tempout.servicePortNumber = $service[1] | |
| $tempout.serviceProto = $service[2] | |
| $tempout.serviceDescription = ($service[3].split('<'))[0] | |
| $tempout.serviceIDConfidenceLevel = (($service[3].split('<'))[1]).split('%')[0] | |
| $csvoutput.add($tempout) | |
| } | |
| } | |
| } | |
| write-host "enumerated" $csvoutput.count "results" | |
| $csvoutput | export-csv C:\Users\user\Desktop\nmap_10_8_6_0_serviceresults.csv -notypeinfo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment