Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from csv import writer
- log_file = '/Users/mani/Desktop/mysql/ipscan/ip.txt'
- output_file = '/Users/mani/Desktop/mysql/ipscan/output.csv'
- name_to_check = 'MBX_AUTHENTICATION_FAILED'
- with open(log_file,encoding="utf-8") 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()
- with open(output_file, 'w') as outfile:
- csv_writer = writer(outfile)
- csv_writer.writerow(["Username","Date","Time","Ip"])
- csv_writer.writerow([username,date,time,ip])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement