Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import re
  2. from csv import writer
  3. log_file = '/Users/mani/Desktop/mysql/ipscan/ip.txt'
  4. output_file = '/Users/mani/Desktop/mysql/ipscan/output.csv'
  5.  
  6. name_to_check = 'MBX_AUTHENTICATION_FAILED'
  7.  
  8. with open(log_file,encoding="utf-8") as infile:
  9.     for line in infile:
  10.         if name_to_check in line:
  11.             username = re.search(r'(?<=userName=\[)(.*)(?=\],)', line)
  12.             username = username.group()
  13.  
  14.             date = re.search(r'([12]\d{3}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]))', line)
  15.             date = date.group()
  16.  
  17.  
  18.             time = re.search(r'(\d{9}\+\d{4})', line)
  19.             time = time.group()
  20.  
  21.             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)
  22.             ip = ip.group()
  23.             with open(output_file, 'w') as outfile:
  24.                 csv_writer = writer(outfile)
  25.                 csv_writer.writerow(["Username","Date","Time","Ip"])
  26.                 csv_writer.writerow([username,date,time,ip])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement