python读取windows日志_Python解析windows系统日志文件
DOM是Document Object Model的簡稱,XML 文檔的高級樹型表示。該模型并非只針對 Python,而是一種普通XML 模型。Python 的 DOM 包是基于 SAX 構(gòu)建的,并且包括在 Python 2.0 的標準 XML 支持里。
參考博客:
python網(wǎng)絡(luò)編程學(xué)習(xí)筆記:XML生成與解析
Python取證技術(shù): Windows 事件日志分析
1.安裝python_Evtx
直接使用pip install python-evtx命令安裝即可
2.感興趣的日志部分篩選
import mmap
import contextlib
from Evtx.Evtx import FileHeader
from Evtx.Views import evtx_file_xml_view
from xml.dom import minidom
def MyFun():
EvtxPath = "D:Application.evtx"
with open(EvtxPath,'r') as f:
with contextlib.closing(mmap.mmap(f.fileno(),0,access=mmap.ACCESS_READ)) as buf:
fh = FileHeader(buf,0)
for xml, record in evtx_file_xml_view(fh):
#只輸出事件ID為4624的內(nèi)容
InterestEvent(xml,4624)
print ""
# 過濾掉不需要的事件,輸出感興趣的事件
def InterestEvent(xml,EventID):
xmldoc = minidom.parseString(xml)
# 獲取EventID節(jié)點的事件ID
booknode=root.getElementsByTagName('event')
for booklist in booknode:
bookdict={}
bookdict['id']=booklist.getAttribute('id')
bookdict['head']=booklist.getElementsByTagName('head')[0].childNodes[0].nodeValue.strip()
bookdict['name']=booklist.getElementsByTagName('name')[0].childNodes[0].nodeValue.strip()
bookdict['number']=booklist.getElementsByTagName('number')[0].childNodes[0].nodeValue.strip()
bookdict['page']=booklist.getElementsByTagName('page')[0].childNodes[0].nodeValue.strip()
if EventID == eventID:
print xml
if __name__ == '__main__':
MyFun()1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
總結(jié)
以上是生活随笔為你收集整理的python读取windows日志_Python解析windows系统日志文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android复杂列表滑动卡顿,Andr
- 下一篇: python 3.5.2页面_Pytho