-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
48 lines (42 loc) · 1.38 KB
/
Copy pathstart.py
File metadata and controls
48 lines (42 loc) · 1.38 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
##Dixon Styres
##secuPy
#Load in data, train model, listen for traffic and classify it.
import loader
import model
from socket import *
class TCPListen():
def __init__(self, trainData, trainLabel, testData, testLabel,l1):
self.m1 = model.KNNModel(trainData, trainLabel, testData, testLabel)
self.l1 = l1
self.m1.run()
#replace localhost if needed for remote server
self.hostname = "student.cs.appstate.edu"
self.port = 15016
def listen(self):
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((self.hostname, self.port))
#Input loop
while 1:
# Read line from server
log = clientSocket.recv(1024)
#send sentence to classifier
sd = self.l1.format(log)
type = self.m1.predict(sd)
#Check if we are done
if(log == 'QUIT'):
print "Connection Terminated"
break
if(type[0] == 1):
print("BOTNET DETECTED")
print(log)
# Close the socket
clientSocket.close()
if __name__ == "__main__":
l1 = loader.Loader("flowdata.binetflow")
data = l1.load()
trainData = data[0]
trainLabel = data[1]
testData = data[2]
testLabel = data[3]
listener = TCPListen(trainData, trainLabel, testData, testLabel,l1)
listener.listen()