attackBehaviorOfDestination = bhvOfTop10IP(attackRaw, attackTopXDstIP) normalBehaviorOfSource = bhvOfTop10IP(normalRaw, normalTopXSrcIP) normalBehaviorOfDestination = bhvOfTop10IP(normalRaw, normalTopXDstIP) BehaviorOfTopIP = { 'attackBehaviorOfSource': attackBehaviorOfSource, 'attackBehaviorOfDestination': attackBehaviorOfDestination, 'normalBehaviorOfSource': normalBehaviorOfSource, 'normalBehaviorOfDestination': normalBehaviorOfDestination, } sc.stop() StatisticsSchema = { 'user': '******', 'AveragePacketRate': AveragePacketRate, 'AveragePacketData': AveragePacketData, 'AverageProtocolRate': AverageProtocolRate, 'ProtocolDistribution': ProtocolDistribution, 'BehaviorOfTopIP': BehaviorOfTopIP } from sendToMongo import sendToMongo sendToMongo(StatisticsSchema) stop = timeit.default_timer() print 'total running time: ', stop - start # print "********************************" # print "********************************" # print "********************************" # print StatisticsSchema
from sendToMongo import sendToMongo from geoip2 import database geoDBpath = '/home/worker/workspace/DeepDefense_dataStatistics/geoDB/GeoLite2-City.mmdb' # geoPath = os.path.join(geoDBpath) # sc.addFile(geoPath) readerLocal = database.Reader(geoDBpath) def ip2CountryLocal(ip): try: country = readerLocal.city(ip).country.name except: country = 'not found' return country c = {'aaa':ip2CountryLocal('128.101.101.101')} sendToMongo(c)