Exemplo n.º 1
0
def cadastrar(nome, mensagem):
    dados = {
        'nome': nome,
        'mensagem': mensagem,
        'hora': time.stftime('%d/%m/%Y %H:%M:%S'),
    }
    db.chat.insert(dados)  # modulo de inserção do mongodb
Exemplo n.º 2
0
def datetime_timestamp(dt, type='ms'):
    if isinstance(dt, str):
        try:
            if len(dt) == 10:
                dt = datetime.strptime(dt.replace('/', '-'), '%Y-%m-%d')
            elif len(dt) == 19:
                dt = datetime.strptime(dt.replace('/', '-'), '%Y-%m-%d %H:%M:%S')
            else:
                raise ValueError()
        except ValueError as e:
            raise ValueError(
                "{0} is not supported datetime format." \
                "dt Format example: 'yyyy-mm-dd' or yyyy-mm-dd HH:MM:SS".format(dt)
            )

    if isinstance(dt, time.struct_time):
        dt = datetime.strptime(time.stftime('%Y-%m-%d %H:%M:%S', dt), '%Y-%m-%d %H:%M:%S')

    if isinstance(dt, datetime):
        if type == 'ms':
            ts = int(dt.timestamp()) * 1000
        else:
            ts = int(dt.timestamp())
    else:
        raise ValueError(
            "dt type not supported. dt Format example: 'yyyy-mm-dd' or yyyy-mm-dd HH:MM:SS"
        )
    return ts
Exemplo n.º 3
0
def datetime_timestamp(dt, type='ms'):
    """datetime2timestamp
    :param dt:datetime格式数据
    :param type: 时间戳类型,ms即millisecond timestamp
    :return: timestamp格式数据
    """
    if isinstance(dt, str):
        try:
            if len(dt) == 10:
                dt = datetime.datetime.strptime(dt, '%Y/%m/%d')
            elif len(dt) == 19:
                dt = datetime.datetime.strptime(dt, '%Y/%m/%d %H:%M:%S')
            elif len(dt) == 18:
                dt = datetime.datetime.strptime(dt, '%Y/%m/%d %H:%M:%S')
            elif len(dt) == 17:
                dt = datetime.datetime.strptime(dt, '%Y/%m/%d %H:%M:%S')
            else:
                raise ValueError()
        except ValueError as e:
            raise ValueError(
                "{0} is not supported datetime format." \
                "dt Format example: 'yyyy/mm/dd' or yyyy/mm/dd HH:MM:SS".format(dt)
            )

    if isinstance(dt, time.struct_time):
        dt = datetime.datetime.strptime(time.stftime('%Y/%m/%d %H:%M:%S', dt),
                                        '%Y/%m/%d %H:%M:%S')

    if isinstance(dt, datetime.datetime):
        if type == 'ms':
            ts = int(dt.timestamp()) * 1000
        else:
            ts = int(dt.timestamp())
    else:
        raise ValueError(
            "dt type not supported. dt Format example: 'yyyy/mm/dd' or yyyy/mm/dd HH:MM:SS"
        )
    return ts
Exemplo n.º 4
0
 def getClock(self):
     if self.clockShowSeconds == True:
         return str(time.strftime(" %2d %b %H:%M:%S"))
     else:
         return str(time.stftime("%a %b %H:%M"))
Exemplo n.º 5
0
def _compare(array):
    if os.path.isfile('log'):
        #file exists
        last = []

        cur = array[:]
        f = open('log','r')
        last = f.read().splitlines()

        s1 = set(cur)
        s2 = set(last)
		
        PortChangeLog = open('PortchangeLog','a')
        if s1.difference(s2):
            changetime = time.localtime(time.time())
            for array in s1.difference(s2):
                PortChangeLog.write("open  "+time.strftime('%Y-%m-%d %H:%M:%S' ,time.localtime(time.time()))+" "+array+"\n")
                if array.split(' ')[5] == "LISTENING":
                    _thread.start_new_thread(_update, ("5", time.strftime('%Y-%m-%d %H:%M:%S', changetime), "Listening port open", array[0:-5], lock))
                    #Listsning port open, go into tracking and behavior analyze module
                    _thread.start_new_thread(_pml_analyze, (time.strftime('%Y-%m-%d %H:%M:%S', changetime), lock))
                    _thread.start_new_thread(_cpl_analyze, (time.strftime('%Y-%m-%d %H:%M:%S', changetime), 'any', lock))
                if array.split(' ')[5] == "ESTABLISHED":
                    hit = 0
                    desIP = array.split(' ')[3]

                    #check whitelist exist
                    if os.path.isfile('whitelist') != True:
                        f = open('whitelist','a')
                        f.close()
                    else:
                        #check whitelist
                        f = open('whitelist','r')
                        if os.stat('whitelist').st_size != 0:    
                            for line in f.read().splitlines():
                                if desIP == line.split(',')[0]:
                                    hit = 1
                        f.close()

                    if hit == 1:
                        #Whitelist match, update cache
                        _thread.start_new_thread(_whitelist, (desIP,lock))

                    if hit == 0:
                        #check blacklist
                        f = open('blacklist','r')
                        for line in f.read().splitlines():
                            if desIP == line:
                                hit = 1
                                #Blacklist match, report and tracking module start
                                _thread.start_new_thread(_update, ('30', time.strftime('%Y-%m-%d %H:%M:%S', changetime), 'BlackList Match', array[0:-5], lock))
                                _thread.start_new_thread(_pml_analyze, (time.stftime('%Y-%m-%d %H:%M:%S', changetime), lock))
                        f.close()

                    if hit == 0:
                        #New connection Not hit White/BlaclList, go into behavior analyze module
                        _thread.start_new_thread(_cpl_analyze, (time.strftime('%Y-%m-%d %H:%M:%S', changetime), desIP, lock))			
                    
        if s2.difference(s1):
            for array in s2.difference(s1):
                PortChangeLog.write("Close  "+time.strftime('%Y-%m-%d %H:%M:%S' ,time.localtime(time.time()))+" "+array+"\n")
        PortChangeLog.close()
		
        f.close()
    else:
        #file not exists
        pass
    return 0
Exemplo n.º 6
0
 def getClock(self):
   if self.clockShowSeconds == True:
     return str(time.strftime(" %2d %b %H:%M:%S"))
   else:
     return str(time.stftime("%a %b %H:%M"))
Exemplo n.º 7
0
# coding: utf-8
import time
time.stftime('%Y-%m-%d %H:%M:%S', '2018-09-12 12:12:12')
time.strptime('%Y-%m-%d %H:%M:%S', '2018-09-12 12:12:12')
time.strstime('%Y-%m-%d %H:%M:%S', '2018-09-12 12:12:12')
time.strptime('2018-09-12 12:12:12', "%Y-%m-%d %H:%M:%S")
time.strptime('2018-09-12 12:12:12', "%Y-%m-%d")
time.strptime('2018-09-12 12:12:12', "%Y-%m-%d %H:%M:%S")
t = time.strptime('2018-09-12 12:12:12', "%Y-%m-%d %H:%M:%S")
t
dir(t)
time.mktime(t)
ss = time.mktime(t)
datetime.datetime.fromtimestamp(ss)
import datetime
datetime.datetime.fromtimestamp(ss)
datetime.datetime.fromtimestamp(ss).date
datetime.datetime.fromtimestamp(ss).date()
d =datetime.datetime.fromtimestamp(ss).date()
str(d)
datetime.datetime('2018-09-12 12:12:12')
dir(datetime)
dir(datetime.time)
from datetime import datetime
datetime.strptime('2018-08-12 12:12:21', "%Y-%m-%d %H:%M:%S")
datetime.strptime('2018-08-12 12:12:21', "%Y-%m-%d %H:%M:%S").date()
import pandas as pd
d =[array([10,  1,  7,  3]),
 array([ 0, 14, 12, 13]),
 array([ 3, 10,  7,  8]),
 array([7, 5]),