惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 吴尔平

gtest 的彩色信息输出 + boost.test 的内存泄漏检测及定位 在低版本的 vc 中使用 vc 10.0 的新特性 使用另一个blog: http://blog.csdn.net/WuErPing scons + swig 如何在 vista 使用 Device Emulator 连接internet vc9 Feature Pack Beta tr1 的一些问题 NSIS Kill Process (转贴) C#与一个彩票页面 - 吴尔平 - 博客园 py2exe 转换 pytetris - 吴尔平 关于模板化的friend class C# 的 random shuffle IronPython 1.0 Release Candidate (转贴 ( 据说比c实现的快1.5!) ) Visual Studio Service Pack (转贴) The 16th Annual Jolt Product Excellence Award Winners (转贴) C++/CLI FAQ (逐步整理中) C++/CLI singleton模式 (双重检测锁实现) 如何在 VS2005 的 Team Unit Testing frameworks 中测试 Native Code (C++ ) 2005 CRT memory leaks 改变 SQL Server 2000 所有对象的所有者
python 读取 windows event log 的简短代码
吴尔平 · 2006-10-20 · via 博客园 - 吴尔平

   最近要把远程机器上的事件日志拿回本地分析,不过不管是直接在事件查看器另存还是用dumpel.exe备份,都不是很合自己心意。我一时又没找到更好的工具,不过手里有python啊。下面是简单的源代码,仅满足自已目前的需要

 1 # -*- coding: cp936 -*-
 2 def Usage():
 3     print '-f windows event log .evt格式备份'
 4     print '-o 输出文件'
 5     print '-logtype event log类型,默认为 Application'
 6 
 7 def Opts(param):
 8     import sys, getopt
 9     try:
10         opts, args = getopt.getopt(sys.argv[1:], "h?f:o:logtype:")
11     except :
12         Usage()
13         return False
14     
15     for opt, val in opts:
16         if opt == '-f':
17             param['f'= val
18         if opt == '-o':
19             param['o'= val
20         if opt == '-logtype':
21             param['logtype'= val
22         if opt in ['-h''-?']:
23             Usage()
24             return False
25     if(param['f'== ''):
26         Usage()
27         return False
28     if(param['o'== ''):
29         param['o'= param['f'+ ".txt"
30     return True
31 
32 def PrintEventLogInfo(records, outfile, sourceNames, logtype):
33     import win32evtlogutil
34     for record in records:
35         try:
36             for srcname in sourceNames:
37                 if str(record.SourceName)==srcname:
38                     outfile.write('//////////////////////////////////////\n')
39                     outfile.write(win32evtlogutil.SafeFormatMessage(record, logtype).encode("mbcs").replace('\r'''))
40         except:
41             continue;
42 
43 def Dump():
44     import win32evtlog
45     param = {'f':'''o':'''logtype':'Application'}
46     sourceNames = ['ASP.NET 2.0.50727.0''']
47     if not Opts(param):
48         return
49     h=win32evtlog.OpenBackupEventLog(None, param['f'])
50     flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
51     outfile = open(param['o'], 'w')
52     while True:
53         records=win32evtlog.ReadEventLog(h, flags, 0)
54         if not records:
55             break;
56         PrintEventLogInfo(records, outfile, sourceNames, param['logtype'])
57     win32evtlog.CloseEventLog(h)
58 
59 if __name__=='__main__':
60     Dump()
61     
62 

simpledump.py -2006-10-19-app.evt