ka.py
来源:互联网 发布:帝国cms 文字水印 编辑:程序博客网 时间:2024/05/01 11:29
#!/usr/bin/python3
#jason.ge 10th of May 2017
#version 0.a
#py read a file in kasperskyanalyze folder
import sys
CLEANMARKS = ['Backup Copy of Object Created','Disinfected On Restart','Object Blocked','Object Deleted','Object Disinfected','Object Moved To Quarantine']
#def linecheck():
def kascheck(data):
cleanlog = []
uncleanlog = []
currentobj = '###'
cleanedflag = False
count = 0
lastline = 'THIS IS FIRST LINE'
for line in data:
#print('[NO. %d] [current obj = %s] [last obj] = %s'%(count,currentobj,lastline)) #trouble shoot only
count += 1
if not (currentobj in line[0]): #THIS IS NEW OBJ ANJD LAST OBJ HAS FINISHED WE NEED TO SEE IF IT IS CLEANED OR NOT
#print('%s not in %s'%(currentobj,line[0])) #for trouble shoot
if (not cleanedflag) and (currentobj != '###'): #IF LAST OBJ (NOW STILL IN CURRENT OBJ) IS NOT CLEANED
uncleanlog.append('[UNCLEANED] %s %s'%(currentobj,lastline[3]))
cleanedflag = False #RESET CLEANEDFLAG TO FALSE
currentobj = getobject(line[0])
if not cleanedflag:
for mark in CLEANMARKS:
if (mark in line[1] or mark in line[2]):
cleanedflag = True
cleanlog.append('[CLEANED] %s CLEANED %s %s'%(line[0],line[1],line[2]))
lastline = line
return cleanlog,uncleanlog
def frominput():
rawdata = []
while True:
inputcache = input()
if inputcache == 'end':
return rawdata
elif inputcache:
rawdata.append(inputcache)
def readfile(arg):#read certain file into a 2D list.
data = []
if 'i' in arg:
tmp = frominput()
else:
fh = open('./kasperskyanalyze/data.csv')
tmp = fh.readlines()
fh.close()
for i in tmp[1:]:
#linecheck()
i = i.split(',')
data.append(i)
for i in range(len(data)):
data[i][0] = data[i][0].lower()
return(data)
def getobject(line):
p = line.find('/')
if p != -1:
return(line[:p])
else:
return(line)
def main():
if len(sys.argv) == 1 or not ('u' or 'a' in sys.argv[1]):
print('-u\tprint uncleaned only')
print('-a\tprint all records')
print('-i\tget data from input')
sys.exit()
try:
data = readfile(sys.argv[1])
except Exception as err:
print('Error during input')
print(err)
sys.exit()
try:
cleanlog,uncleanlog = kascheck(data)
except Exception as err:
pass
print('=== RESULTS ===')
if 'u' in sys.argv[1]:
for i in uncleanlog:
print(i)
elif 'a' in sys.argv[1]:
for i in cleanlog:
print(i)
for i in uncleanlog:
print(i)
main()
#jason.ge 10th of May 2017
#version 0.a
#py read a file in kasperskyanalyze folder
import sys
CLEANMARKS = ['Backup Copy of Object Created','Disinfected On Restart','Object Blocked','Object Deleted','Object Disinfected','Object Moved To Quarantine']
#def linecheck():
def kascheck(data):
cleanlog = []
uncleanlog = []
currentobj = '###'
cleanedflag = False
count = 0
lastline = 'THIS IS FIRST LINE'
for line in data:
#print('[NO. %d] [current obj = %s] [last obj] = %s'%(count,currentobj,lastline)) #trouble shoot only
count += 1
if not (currentobj in line[0]): #THIS IS NEW OBJ ANJD LAST OBJ HAS FINISHED WE NEED TO SEE IF IT IS CLEANED OR NOT
#print('%s not in %s'%(currentobj,line[0])) #for trouble shoot
if (not cleanedflag) and (currentobj != '###'): #IF LAST OBJ (NOW STILL IN CURRENT OBJ) IS NOT CLEANED
uncleanlog.append('[UNCLEANED] %s %s'%(currentobj,lastline[3]))
cleanedflag = False #RESET CLEANEDFLAG TO FALSE
currentobj = getobject(line[0])
if not cleanedflag:
for mark in CLEANMARKS:
if (mark in line[1] or mark in line[2]):
cleanedflag = True
cleanlog.append('[CLEANED] %s CLEANED %s %s'%(line[0],line[1],line[2]))
lastline = line
return cleanlog,uncleanlog
def frominput():
rawdata = []
while True:
inputcache = input()
if inputcache == 'end':
return rawdata
elif inputcache:
rawdata.append(inputcache)
def readfile(arg):#read certain file into a 2D list.
data = []
if 'i' in arg:
tmp = frominput()
else:
fh = open('./kasperskyanalyze/data.csv')
tmp = fh.readlines()
fh.close()
for i in tmp[1:]:
#linecheck()
i = i.split(',')
data.append(i)
for i in range(len(data)):
data[i][0] = data[i][0].lower()
return(data)
def getobject(line):
p = line.find('/')
if p != -1:
return(line[:p])
else:
return(line)
def main():
if len(sys.argv) == 1 or not ('u' or 'a' in sys.argv[1]):
print('-u\tprint uncleaned only')
print('-a\tprint all records')
print('-i\tget data from input')
sys.exit()
try:
data = readfile(sys.argv[1])
except Exception as err:
print('Error during input')
print(err)
sys.exit()
try:
cleanlog,uncleanlog = kascheck(data)
except Exception as err:
pass
print('=== RESULTS ===')
if 'u' in sys.argv[1]:
for i in uncleanlog:
print(i)
elif 'a' in sys.argv[1]:
for i in cleanlog:
print(i)
for i in uncleanlog:
print(i)
main()
阅读全文
0 0
- ka.py
- kA*与(kA)*的行列式计算
- 夏天的味道 ka
- ka代码问题
- senyum atau bibir Ka
- 【PA2013】【BZOJ3839】Działka
- BZOJ3839: [Pa2013]Działka
- py
- py
- py
- py
- py
- py
- py
- Py
- About Ka-shing Li------one wonderful man.
- RX-93-v GUNDAM VER.KA
- Is Li Ka-shing on the Billionaires' Charity Bandwagon?
- 消息队列的优点解析
- 判断1000~2000年之间的闰年(C语言)
- mysql jdbc
- 初窥Linux 之 我最常用的20条命令
- Android
- ka.py
- 破解网页中鼠标无法复制粘贴文字的几种简单方法
- 如何申请域名并绑定ip
- 如何将svn上的项目下载到本地并转化成maven项目
- 【ASP.net】——必备基础
- Android日夜间模式切换
- 51Nod1046 A^B Mod C(C语言)
- kvm HOST setup
- linux 操作小笔记