All,
Following up with a windows powershell version for this. You pass it the netstat -nao command and it will filter out the listening ports and return them in a list of tuples ex: [(protocol,ipaddress,port),(protocol,ipaddress,port)]. I can further expand on this to include the actual program name, but for now I'm good with just knowing what ports are listening.
Save as netstatParser.ps1 >>
param(
[Parameter(ValueFromPipeline=$true,Position=0)] [string] $Data
)
$Data = $input
$ossec_out = "["
foreach ($line in $input)
{
if ($line -match "(TCP|UDP)\s+([^:]*):(\d+).*LISTENING")
{
$var = "($($matches[1]),$($matches[2]),$($matches[3])),"
$ossec_out += $var
}
}
$ossec_out += "]"
$ossec_out = $ossec_out.replace(",]","]")
write-output $ossec_out
<<
Example usage with full command:
Netstat -nao | .\parseNetstat.ps1
Output Example:
[(TCP,0.0.0.0,135),(TCP,0.0.0.0,445),(TCP,0.0.0.0,2701),(TCP,0.0.0.0,3389),(TCP,0.0.0.0,5985),(TCP,0.0.0.0,7561),(TCP,0.0.0.0,45329),(TCP,0.0.0.0,47001),(TCP,0.0.0.0,49152),(TCP,0.0.0.0,49153),(TCP,0.0.0.0,49154),(TCP,0.0.0.0,49177),(TCP,0.0.0.0,49178),(TCP,0.0.0.0,49183),(TCP,127.0.0.1,55578),(TCP,192.168.222.210,139)]
Again thanks Kevin for the inspiration
Devon J. Greene
PS Pardon my cruddy powershell, it's not really my cup of tea ha.