Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import re
- log_file = 'log.txt'
- output_file = 'output.csv'
- name_to_check = 'MBX_AUTHENTICATION_FAILED'
- max_user_login = 10
- with open(log_file) as infile:
- for line in infile:
- if name_to_check in line:
- username = re.search(r'(?<=userName=\[)(.*)(?=\],)', line)
- username = username.group()
- date = re.search(r'([12]\d{3}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]))', line)
- date = date.group()
- time = re.search(r'(\d{9}\+\d{4})', line)
- time = time.group()
- ip = re.search(r'(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])', line)
- ip = ip.group()
- logs = re.findall('MBX_AUTHENTICATION_FAILED:\{(.*?)\}',line)
- with open(output_file, 'a') as outfile:
- outfile.write(',{username},{date},{time},{ip},{logs}\n'.format(username=username, date=date, time=time, ip=ip,logs=logs))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement