migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
34
automation-sys320/week04/Apache-Logs.ps1
Normal file
34
automation-sys320/week04/Apache-Logs.ps1
Normal file
|
@ -0,0 +1,34 @@
|
|||
# 9/26/24
|
||||
|
||||
# input page name, http code, and browser
|
||||
# output IP addresses that visited the given page, with given browser, and got given HTTP response
|
||||
Function Apache-Logs ([string]$page, [string]$HTTPcode, [string]$browser){
|
||||
$logsnotformatted = Get-Content C:\xampp\apache\logs\access.log
|
||||
$tablerecords = @()
|
||||
|
||||
for($i=0; $i -lt $logsnotformatted.Length; $i++){
|
||||
|
||||
# split string into words
|
||||
$words = $logsnotformatted[$i] -split " "
|
||||
|
||||
# filter out logs that don't match inputs
|
||||
if(($words[6] -inotlike $page) -OR ($words[8] -inotcontains $HTTPcode) `
|
||||
-OR ($words[11].Trim('"') -inotlike $browser)){
|
||||
continue
|
||||
}
|
||||
|
||||
# create custom objects for matches
|
||||
$tablerecords += [pscustomobject]@{"IP" = $words[0]; `
|
||||
"Page" = $words[6]; `
|
||||
"Response" = $words[8]; `
|
||||
"Browser" = -join $words[11..($words.Length - 1)]; }
|
||||
}# end of for loop
|
||||
|
||||
return $tablerecords
|
||||
|
||||
}
|
||||
#$ips1 = Apache-Logs "/index.html" "200" "Mozilla/5.0"
|
||||
#$ips1
|
||||
|
||||
#$ips2 = Apache-Logs "/*external*" "404" "Mozilla/5.0"
|
||||
#$ips2
|
26
automation-sys320/week04/ParsingApacheLogs.ps1
Normal file
26
automation-sys320/week04/ParsingApacheLogs.ps1
Normal file
|
@ -0,0 +1,26 @@
|
|||
# 9/26/24
|
||||
|
||||
# parses apache log into pscustomobjects, filters IPs for 10.*
|
||||
function ApacheLogs1(){
|
||||
$logsnotformatted = Get-Content C:\xampp\apache\logs\access.log
|
||||
$tablerecords = @()
|
||||
|
||||
for($i=0; $i -lt $logsnotformatted.Length; $i++){
|
||||
|
||||
# split string into words
|
||||
$words = $logsnotformatted[$i] -split " "
|
||||
|
||||
$tablerecords += [pscustomobject]@{"IP" = $words[0]; `
|
||||
"Time" = $words[3].Trim('['); `
|
||||
"Method" = $words[5].Trim('"'); `
|
||||
"Page" = $words[6]; `
|
||||
"Protocol" = $words[7]; `
|
||||
"Response" = $words[8]; `
|
||||
"Referrer" = $words[10]; `
|
||||
"Client" = -join $words[11..($words.Length - 1)]; }
|
||||
}# end of for loop
|
||||
|
||||
return $tablerecords | Where-Object { $_.IP -ilike "10.*"}
|
||||
}
|
||||
$tablerecords = ApacheLogs1
|
||||
#$tablerecords
|
41
automation-sys320/week04/WindowsApacheLogs.ps1
Normal file
41
automation-sys320/week04/WindowsApacheLogs.ps1
Normal file
|
@ -0,0 +1,41 @@
|
|||
# 2. list all the apache logs of XAMPP
|
||||
Get-Content C:\xampp\apache\logs\access.log
|
||||
|
||||
# 3. list last 5 lines of the apache logs of XAMPP
|
||||
Get-Content C:\xampp\apache\logs\access.log -Tail 5
|
||||
|
||||
# 4. display only 404 and 400 errors
|
||||
Get-Content C:\xampp\apache\logs\access.log | Select-String ' 404 ', ' 400 '
|
||||
|
||||
# 5. display all logs that are NOT code 200
|
||||
Get-Content C:\xampp\apache\logs\access.log | Select-String ' 200 '
|
||||
|
||||
# 6. from every file with .log extension, get those that contain the word '-error'
|
||||
$A = Get-ChildItem C:\xampp\apache\logs\*.log | Select-String 'error'
|
||||
# select last 5 from array
|
||||
$A[-5..-1]
|
||||
|
||||
# 7. display ip addresses for 404 errors
|
||||
$notfounds = Get-Content C:\xampp\apache\logs\access.log | Select-String ' 404 '
|
||||
$regex = [regex] "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
|
||||
$ipsunorganized = $regex.Matches($notfounds)
|
||||
|
||||
$ips = @()
|
||||
for($i=0; $i -lt $ipsunorganized.Count; $i++){
|
||||
$ips += [pscustomobject]@{ "IP" = $ipsunorganized[$i].Value; }
|
||||
}
|
||||
$ips | Where-Object { $_.IP -ilike "10.*" }
|
||||
|
||||
# 8. count ips from previous output
|
||||
$ipsoftens = $ips | Where-Object { $_.IP -ilike "10.*" }
|
||||
$counts = $ipsoftens | Group-Object IP
|
||||
$counts | Select-Object Count, Name
|
||||
|
||||
|
||||
# 9
|
||||
# run external script Apache-Logs.ps1
|
||||
#(Join-Path $PSScriptRoot C:\Users\champuser\SYS320\week4\Apache-Logs.ps1)
|
||||
. "C:\Users\champuser\SYS320\week4\Apache-Logs.ps1"
|
||||
|
||||
$ips = Apache-Logs "/*external*" "404" "Mozilla/5.0"
|
||||
#$ips
|
Loading…
Add table
Add a link
Reference in a new issue