Advertisement
Guest User

capt-user.py

a guest
May 26th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import re
  5.  
  6.  
  7. log_file = 'log.txt'
  8. output_file = 'output.csv'
  9.  
  10. name_to_check = 'MBX_AUTHENTICATION_FAILED'
  11. max_user_login = 10
  12.  
  13. with open(log_file) as infile:
  14.     for line in infile:
  15.         if name_to_check in line:
  16.             username = re.search(r'(?<=userName=\[)(.*)(?=\],)', line)
  17.             username = username.group()
  18.  
  19.             date = re.search(r'([12]\d{3}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]))', line)
  20.             date = date.group()
  21.  
  22.             time = re.search(r'(\d{9}\+\d{4})', line)
  23.             time = time.group()
  24.  
  25.             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)
  26.             ip = ip.group()
  27.            
  28.             logs = re.findall('MBX_AUTHENTICATION_FAILED:\{(.*?)\}',line)
  29.             with open(output_file, 'a') as outfile:
  30.                 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