-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (22 loc) · 917 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
import pythonApacheLibrary.apacheLogs as apl
import pythonApacheLibrary.apacheML as aml
import pythonApacheLibrary.blacklistHandler as blh
accessLogPath = ''
ipBlackListCsv = ""
ipDBkey = ""
ipBlackListConf = ""
# Read in access_log file & Parse File to return relevant columns
accessLog = apl.accessLogInit(accessLogPath).head(10)
# Compare list of Ips to current blacklisted DB
ipList = pd.read_csv(ipBlackListCsv)
# Drop Rows where there is overlap
accessLog = accessLog[~accessLog['Ip'].isin(ipList["IPBlack"])]
# Perform IP Lookup funciton
accessLog = apl.reverseIpLookup(accessLog, ipDBkey)
# Perform Label Encoding
# Run each new row through decision tree
predictedDF = aml.apacheMLProcess(accessLog)
predictedDF = predictedDF[predictedDF['Prediction'] == 3]
# If flagged as bad, append IPs to blacklist in APACHE
blh.blacklistAppender(predictedDF, ipBlackListConf, ipBlackListCsv)