#!env python
# -*- coding: <encoding name> -*-
import sys
from scapy.all import *
import os,random,datetime,time,math
from random import randrange
from random import uniform
from functools import reduce
def create_data(line):
current_time = [
datetime.datetime.now().strftime('%b %d %H:%M:%S'),
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
# datetime.datetime.now().strftime('%b %d %H:%M:%S %Y'),
str(math.trunc(datetime.datetime.now().timestamp()))
]
regular = [
"(\w{3}\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2})",
"(\d{4}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2})",
"(\w{3}\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2}\s+\d{1,4})",
"(\d{10})"
]
def current_time(line):
for i in regular:
for j in current_time(line):
if len(re.findall(i, j)) != 0: #若正则匹配上相对应的时间格式,则对字符串进行替换
line=re.sub(i,j,line)
return line
dict_ip_logfile={
"192.168.58.84": r"C:\Users\CS\Desktop\HPHIDS.txt"
}
while True:
for ip,logfile in dict_ip_logfile.items():
with open(logfile,"r",encoding='unicode_escape') as log:
for line in log:
print(ip)
print(logfile)
print(create_data(line))
# IP = (porto='udp','192.168.57.45')
# UDP = (dst='192.168.57.14',8089)
# scapy.all,send(IP,udp)
scapy.all.send(IP(proto="udp",src=ip,dst="192.168.57.45")/udp(dst='192.168.57.14.',dport=8082)/line,inter=5,loop=1,count=2)
log.close()