在Python中使用来自Pywin32的win32evtlog,不寻常的event.EventID数字如-2147481364。

问题描述 投票:0回答:2

我写了一个python(3.2)脚本来禁止Windows 2008服务器的事件日志中的某些事件的ips,我想测试它是否能正确禁止sql强制尝试的ips。不幸的是,到目前为止,它还没有到达代码的那部分,因为它正在寻找的事件ID从来没有出现过(尽管它应该出现,因为它在日志文件中)。

def run_script_application_log():
    eventIds = [18456] #look for these events to process for possible ip bans 18456 = failed login
    server = 'localhost' # name of the target computer to get event logs from
    logtype = 'Application' # 'Application' or 'Security' etc...
    hand = win32evtlog.OpenEventLog(server,logtype)
    ipsToBan = look_for_ips_to_ban(hand,flags,eventIds)

def look_for_ips_to_ban(hand, flag, eventIds):
    ...some code....
    events=1
    while events:
        events=win32evtlog.ReadEventLog(hand,flag,0)
        for event in events:
            the_time=event.TimeGenerated.Format()
            seconds=date2sec(the_time)
            #if seconds < begin_sec - time_in_seconds: break
            if event.EventID in eventIds:

我插入了一个简单的打印语句来查看event.EventID是怎么回事,它获得的数字至少可以说是奇怪的。事件日志上升到33090,但绝大多数返回的ID类似于这些:10737500201073754112-1073741823-2147481364。

我不知道是怎么回事。用安全日志可以正常工作,但是应用日志好像就不行了。

我查看了一些数据,除了事件ID之外,似乎都能正确报告。

例如,日志中的这条记录除了显示事件ID为1073742726而不是18456之外,其他都是正确的。

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="MSSQLSERVER" /> 
<EventID Qualifiers="49152">18456</EventID> 
<Level>0</Level> 
<Task>4</Task> 
<Keywords>0x90000000000000</Keywords> 
<TimeCreated SystemTime="2012-12-08T18:01:32.000000000Z" /> 
<EventRecordID>4532</EventRecordID> 
<Channel>Application</Channel> 
<Computer>windowsmachine</Computer> 
<Security /> 
</System>
<EventData>
<Data>username</Data> 
<Data>Reason: Password did not match that for the login provided.</Data> 
<Data>[CLIENT: <local machine>]</Data
<Binary>184800000E0000000A000000570049004E004D00430041005000460058000000070000006D00610073007400650072000000</Binary> 
</EventData>
</Event>
python event-log pywin32 event-id
2个回答
1
投票

如果你检查它的二进制函数工作正常,它只是增加了1位(或更多,没有真正检查它),你不需要。

answer=event.EventID & 0x1FFFFFFF

© www.soinside.com 2019 - 2024. All rights reserved.