Last active
December 1, 2016 20:17
-
-
Save nullbind/d1ea79cf0284b5b667b9a63a326f912c to your computer and use it in GitHub Desktop.
hacky ps script to convert ip,openport to ip, allopenports
This file contains 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
# hacky ps script to convert ip,openport to ip,allopenports | |
# Container for final list | |
$FullList = New-Object System.Data.DataTable | |
$FullList.Columns.Add("Dest") | Out-Null | |
$FullList.Columns.Add("Port") | Out-Null | |
# import full list of open ports – one per line (dest,port) | |
$ImportList = import-csv C:\temp\open-ports-by-line.csv | |
# Create unique ip list | |
$IPs = $ImportList | Select-Object dest -Unique | |
# loop through ips | |
$IPs | | |
ForEach-Object { | |
$IP = $_.Dest | |
# loop through full list | |
$ImportList | | |
ForEach-Object{ | |
$Dest = $_.Dest | |
$Port = $_.Port | |
# check if it is current ip | |
if($IP -eq $Dest){ | |
# build port list | |
$ports = "$ports $port," | |
$GoodDest = $_.Dest | |
$GoodPort = $_.Port | |
} | |
} | |
# remove trailing | |
$ports = $ports.Substring(0,$ports.Length-1) | |
# Add ip info to final list | |
$FullList.Rows.Add($GoodDest,$ports) |out-null | |
# clear port list | |
$ports = "" | |
} | |
# return list and write to file | |
$FullList | |
$FullList | Export-Csv -NoTypeInformation c:\temp\open-ports-summary-by-ip.csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment