Created
May 31, 2018 06:29
-
-
Save neduma/ab50eb1701420074881a9d60a41c9515 to your computer and use it in GitHub Desktop.
auth.log failed ip count
This file contains 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
#!/usr/bin/env python | |
import requests | |
import re | |
""" Extract failed ip from auth.log and with number of attempts """ | |
log_url = "https://gist.githubusercontent.com/bholt/0b95ea35283b49bacd4a68d3970097fa/raw/c4335e725c0c87973e4fdb5069f06056763fbaa0/short.txt" | |
def get_file(): | |
req = requests.get(log_url) | |
return req.text | |
def extract_ip(): | |
lines = get_file().split('\n') | |
attempts = dict() | |
regex2 = r"\s+(\d+\.\d+\.\d+\.\d+)\s+" | |
for line in lines: | |
if re.search(regex2, line): | |
match = re.search(regex2, line) | |
failed_ip = match.group(1) | |
if failed_ip in attempts: | |
attempts[failed_ip] += 1 | |
else: | |
attempts[failed_ip] = 1 | |
print(attempts) | |
def main(): | |
extract_ip() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment