Das Ziel ist es, diese awk-Datei zu übernehmen:Powershell-Protokolldateiverarbeitung
#!/usr/bin/awk -f
BEGIN { LastSource = "" # BEGIN Block
ORS = "" # ORS set to default a.k.a newline
Sources = 0 # Variable created and set to 0
Ports = 0 # Variable created and set to 0
FS = ":" # Field Seperator set to a colon
} # End of the BEGIN Block
{ # Open Block
if ($1 != LastSource){ # First Field not = Last Source execute following
ORS = "\n"
print " " # formatting
ORS = " " # ORS set to space for same line print
print $1, $2 # printing Source IP and Destination Port
LastSource = $1 # set LastSource to SourceIP
Sources += 1 # Increment Source by 1
Ports += 1 # Increment Ports by 1
} else {
ORS = " "
print $2 # Print DestPort to current line (multi port per IP)
Ports += 1 # Increment Ports by 1
}
}
END { ORS = "\n" # END Block execute after last line is read
print "\n\n" "Total Sources = ", Sources # Print two new lines and text followed by the variable Sources
print "Unique Ports Scanned = ", Ports # Print text followed by the variable Ports
}
# Command Line:
# grep 'INext-DROP-DEFLT' sample.log.txt | sed -e 's/.*SRC=//' -e 's/ .*DPT=/:/' -e 's/ .*//' | sort | uniq | awk -f Lab3Submission.awk
Und konvertieren Sie es über Powershell in eine äquivalente Ausgabe.
Im Moment habe ich den folgenden Befehl
gc sample.log | sls "INext-DROP-DEFLT" | ForEach-Object { $_.line -match "SRC=(.*?)\s" > $null;$matches[1] + ":" + $matches[2] } | sort | Get-Unique | ForEach-Object -Begin { $LastSource = " "; $sources = 0; $ports = 0; } -process { $ip = $_.split(":")[0]; $port = $_.split(":")[1]; if($1 -ne $LastSource){print $1, $2 $LastSource = $1 $sources += 1 $Ports += 1 } else { print $2 $Ports += 1 } } END { print "\n\n" "Total Sources = ", $sources p
rint "Unique Ports Scanned = ", $Ports }
Unsicher, wie Sie vorgehen.
Log-Datei für Referenz: LogFileTinyUplaod
Dies war genau das, was ich gesucht habe. Ich werde es ein wenig mehr bearbeiten müssen, da es nicht die richtigen Endzahlen ausgibt, aber das macht für mich viel mehr Sinn. –