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

2022-05-24 16:24:26 +08:00
 colitude

在公网的服务器,虽然改了端口和默认用户名,还是有有很多 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 就行了 这个帖子的回复里有提到一句,可是没有详细说

730 次点击
所在节点    程序员
1 条回复
colitude
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>]
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/854993

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX