SHARE
TWEET

parse-nmap.ps1

a guest Nov 19th, 2012 61 Never
  1. [cmdletbinding()]
  2. param (
  3.     [string[]]$targets
  4. )
  5. cls
  6.  
  7. foreach ($targetHost in $targets){
  8.     [xml]$nmapResults = nmap -Pn -oX - $targetHost;
  9.     $portResults = @();
  10.         foreach ($port in $nmapresults.nmaprun.host.ports.port){
  11.             $portinfo = New-Object System.Object;
  12.             $portinfo|add-member -membertype noteproperty -name hostname -value $targetHost;
  13.             $portinfo|add-member -membertype noteproperty -name protocol -value $($port.protocol);
  14.             $portinfo|add-member -membertype noteproperty -name portid -value $($port.portid);
  15.             $portinfo|add-member -membertype noteproperty -name state -value $($port.state.state);
  16.             $portinfo|add-member -membertype noteproperty -name reason -value $($port.state.reason);
  17.             $portinfo|add-member -membertype noteproperty -name reason_ttl -value $( $port.state.reason_ttl);
  18.             $portinfo|add-member -membertype noteproperty -name servicename -value $($port.service.name);
  19.             $portinfo|add-member -membertype noteproperty -name method -value $($port.service.method);
  20.             $portinfo|add-member -membertype noteproperty -name conf -value $($port.service.conf);
  21.             $portResults += $portinfo;
  22.     }
  23. }
  24. $portresults |ft -auto;
RAW Paste Data
Top