Beispiel #1
0
	def calculate_user_agents(self, incidents):
		es_handler = ESHandler(self.bothound_tools.es_user, self.bothound_tools.es_password,
				self.bothound_tools.es_host, self.bothound_tools.es_port)
		res = []
		for i in incidents:
			incident = self.bothound_tools.get_incident(i)[0]
			res_dict = es_handler.get_banned_user_agents(incident['start'], incident['stop'], incident['target'])

			res_list = []
			for key, value in res_dict.iteritems():
				temp = [key,value]
				res_list.append(temp)

			res_sorted = sorted(res_list, key=lambda k: k[1], reverse=True) 
			num_most = len(res_sorted) if len(res_sorted) < 50 else 50
			print "incident", i, "winner", res_sorted[0]
			res.append(res_sorted[0:num_most])

		i = 1
		f1=open('user_agents.txt', 'w+')
		for incident in res:
			print >>f1, "incident", i
			print "incident", i
			i = i + 1
			for r in incident:
				print >> f1, r[0], r[1] 
				print r[0], r[1] 
		f1.close()
Beispiel #2
0
    def calculate_user_agents(self, incidents):
        es_handler = ESHandler(self.bothound_tools.es_user,
                               self.bothound_tools.es_password,
                               self.bothound_tools.es_host,
                               self.bothound_tools.es_port)
        res = []
        for i in incidents:
            incident = self.bothound_tools.get_incident(i)[0]
            res_dict = es_handler.get_banned_user_agents(
                incident['start'], incident['stop'], incident['target'])

            res_list = []
            for key, value in res_dict.iteritems():
                temp = [key, value]
                res_list.append(temp)

            res_sorted = sorted(res_list, key=lambda k: k[1], reverse=True)
            num_most = len(res_sorted) if len(res_sorted) < 50 else 50
            print "incident", i, "winner", res_sorted[0]
            res.append(res_sorted[0:num_most])

        i = 1
        f1 = open('user_agents.txt', 'w+')
        for incident in res:
            print >> f1, "incident", i
            print "incident", i
            i = i + 1
            for r in incident:
                print >> f1, r[0], r[1]
                print r[0], r[1]
        f1.close()