Optimized by not reading the entire log file into memory
This commit is contained in:
parent
09b57cdf06
commit
683f5de32c
@ -10,15 +10,16 @@ def main():
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
with open(input_file, "r") as f:
|
||||
# Read log file
|
||||
lines = f.readlines()
|
||||
|
||||
# keep track of both the total number of authentication failures and the number of failures from each IP address
|
||||
auth_failures = {}
|
||||
total = 0
|
||||
|
||||
for line in lines:
|
||||
with open(input_file, "r") as f:
|
||||
# Read log file
|
||||
for line in f:
|
||||
# check for auth failure in line
|
||||
# NOTE: This is a rudimentary check, and will not work for all log formats. This was chosen for the log file provided.
|
||||
# as an example, it will not work when the failure arises from PAM, as those logs are formatted differently
|
||||
if "authentication failure" in line:
|
||||
# add failure
|
||||
total += 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user