def do_POST(self): # Parse the form data posted form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': self.headers['Content-Type'], }) # Begin the response self.send_response(200) self.end_headers() self.wfile.write('\n') message = threading.currentThread().getName() self.wfile.write(message) self.wfile.write('\n') self.wfile.write('Client: %s\n' % str(self.client_address)) self.wfile.write('Path: %s\n' % self.path) user = form['user'].value if 'switch' in form: switch = form['switch'].value DIM.setLearningMode(user, switch) else: vectortype = form['datatype'].value data = json.loads(form['json'].value) Runner.Run(data, user, vectortype) return
def detectNetworkAnomalies(passedData, username): # Get the trained data set trainedData = DatabaseInteractionClass.getNetworkLearnedData(username) npTrainedData = np.array(trainedData) # Generate the model, and fit the trained data to it clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.00005) clf.fit(npTrainedData) # This should return an array of 1's and -1's (in float64 form), the -1's corresponding to failures return clf.predict(passedData)
def detectProcessAnomalies(passedData, username): # Get the trained data set trainedData = DatabaseInteractionClass.getProcessLearnedData(username) #scaledTrainingData = [] #scaledPassedData = [] #for point in trainedData: # scaledTrainingData.append(AnomalyDetectionClass.scalePoint(point)) #for point in passedData: # scaledPassedData.append(AnomalyDetectionClass.scalePoint(point)) print "in detect process anomalies" print "training data:" print trainedData print "input data:" print passedData npTrainedData = np.array(trainedData) #npTrainedData = np.array(scaledTrainingData) # Generate the model, and fit the trained data to it clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.00005) clf.fit(npTrainedData) # This should return an array of 1's and -1's (in float64 form), the -1's corresponding to failures return clf.predict(passedData)
def getLatLong(ipAddress): latitude, longitude = DatabaseInteractionClass.getLatLongFromIP(ipAddress) return latitude, longitude
from DatabaseInteractionModule import DatabaseInteractionClass as DIM print DIM.getScore("zlbales") print DIM.getScore("cbcullen") print DIM.getPointsProcessed("zlbales") print DIM.getPointsProcessed("cbcullen") print DIM.isLearningMode("zlbales") print DIM.isLearningMode("cbcullen") #integer version of Zach's IP (129.186.251.4) at time of writing test print DIM.getLatLongFromIP(2176514820) #integer version of Google's IP address for DNS server (8.8.8.8) print DIM.getLatLongFromIP((8 * 256 * 256 * 256) + (8 * 256 * 256) + (8 * 256) + 8) print DIM.setScore("zlbales", 99, 10) print DIM.setScore("zlbales", 98, 20) print DIM.setScore("zlbales", 97, 30) print DIM.setScore("zlbales", 100, 0) print DIM.getProcessLearnedData("zlbales") print DIM.getProcessLearnedData("cbcullen") print DIM.getProcessLearnedData("unknown") print DIM.getFileLearnedData("zlbales") print DIM.getFileLearnedData("cbcullen") print DIM.getFileLearnedData("unknown") print DIM.getNetworkLearnedData("zlbales")