Last active
July 16, 2024 13:02
-
-
Save egre55/20d472ec5e649b2c04a52d0e4833b9db to your computer and use it in GitHub Desktop.
IIS-LogParser.ps1
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
# author: @egre55 | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$True)][string]$logfile | |
) | |
$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(600,20000) | |
while($true) | |
{ | |
Write-Output "`nWeb Server Log Interrogator`n" | |
Write-Output "Using log file: $logfile`n" | |
Write-Output "Log contains the following IP addresses (ordered by number of requests):" | |
$content = Get-Content $logfile | |
$regex = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" | |
$regex.Matches($content) | %{ $_.value } | Get-Unique | group | Sort -desc Count | Select Count, Name | Out-Host | |
Write-Output "`nInput an IP address to display count of requested resources.`n" | |
$ip = Read-Host -Prompt '> ' | |
get-content $logfile | select-string -pattern $ip -encoding ASCII > parsed-requests.txt | |
$items = get-content parsed-requests.txt | %{ $_.Split(' ')[4]; } | |
echo $items | Get-Unique | group | Sort -desc Count | Select Count, Name| Out-Host | |
Write-Output "Do you want to see all requests the IP address sent for a particular resource?" | |
$confirmation = Read-Host "Enter (y)es or (n)o)" | |
if (($confirmation -eq 'n') -or ($confirmation -eq 'no')) { | |
exit | |
} else { | |
$resource = Read-Host "Enter the resource - e.g. /admin" | |
Select-String -Path "parsed-requests.txt" -Pattern "$resource" | Select Line | Out-Host | |
Write-Output "Do you want to run another query?" | |
$confirmation = Read-Host "Enter (y)es or (n)o)" | |
if (($confirmation -eq 'n') -or ($confirmation -eq 'no')) { | |
exit | |
} else { | |
continue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment