V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
colitude
V2EX  ›  程序员

请问有什么办法可以读取事件查看器的日志

  •  
  •   colitude · 2022-05-24 16:24:26 +08:00 · 719 次点击
    这是一个创建于 704 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在公网的服务器,虽然改了端口和默认用户名,还是有有很多 ip 尝试爆破登陆,在事件查看器里面可以筛选 4625 看到尝试的登陆失败的 ip ,可以把他们添加到防火墙,可是太多了,手动跟不上,是不是可以读取到事件查看器里的日志,然后我弄个脚本或者程序,把尝试登陆失败三次以上的 ip 自动加入防火墙里,添加防火墙的命令我知道

    netsh advfirewall firewall set rule name="IPBan_Block_0" new remoteip=14.150.206.129/32,45.134.26.151/32
    

    可是不知道怎么自动读取到 ip 。

    另外我用了 IPBan 这个软件,看官网它是通过 monitors log files and event viewer for failed logins. When a number of failed logins exceeds a threshold in a given time, the ip address for those failed logins is added to the firewall 实现的。我也想想自己实现 monitors log files and event viewer 。 C#直接接入 eventlog 就行了 这个帖子的回复里有提到一句,可是没有详细说

    colitude
        1
    colitude  
    OP
       2022-05-24 17:47:20 +08:00
    相信应该找到答案了,晚上试试
    wevtutil

    可让你检索有关事件日志和发布服务器的信息。 此外,还可以使用此命令来安装和卸载事件清单,运行查询,以及导出、存档和清除日志。
    ```
    wevtutil [{el | enum-logs}] [{gl | get-log} <Logname> [/f:<Format>]]
    [{sl | set-log} <Logname> [/e:<Enabled>] [/i:<Isolation>] [/lfn:<Logpath>] [/rt:<Retention>] [/ab:<Auto>] [/ms:<MaxSize>] [/l:<Level>] [/k:<Keywords>] [/ca:<Channel>] [/c:<Config>]]
    [{ep | enum-publishers}]
    [{gp | get-publisher} <Publishername> [/ge:<Metadata>] [/gm:<Message>] [/f:<Format>]] [{im | install-manifest} <Manifest>]
    [{um | uninstall-manifest} <Manifest>] [{qe | query-events} <Path> [/lf:<Logfile>] [/sq:<Structquery>] [/q:<Query>] [/bm:<Bookmark>] [/sbm:<Savebm>] [/rd:<Direction>] [/f:<Format>] [/l:<Locale>] [/c:<Count>] [/e:<Element>]]
    [{gli | get-loginfo} <Logname> [/lf:<Logfile>]]
    [{epl | export-log} <Path> <Exportfile> [/lf:<Logfile>] [/sq:<Structquery>] [/q:<Query>] [/ow:<Overwrite>]]
    [{al | archive-log} <Logpath> [/l:<Locale>]]
    [{cl | clear-log} <Logname> [/bu:<Backup>]] [/r:<Remote>] [/u:<Username>] [/p:<Password>] [/a:<Auth>] [/uni:<Unicode>]
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5696 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 108ms · UTC 06:30 · PVG 14:30 · LAX 23:30 · JFK 02:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.