Python - 创建在authlog中有超过5次失败登录尝试的IP地址的黑名单文件
基本上我有一个 authlog/syslog 文件,其中包含登录尝试和 IP 地址的列表 - 我需要制作一个 Python 程序,该程序将创建一个 txt 文件,其中包含超过 5 次失败登录尝试的所有 IP 地址 - 一种“黑名单”。
所以基本上是这样的:
如果“uniqueipaddress”和“authentication failure”出现超过5次,则将uniqueipaddress添加到txt文件中。
任何帮助将不胜感激 - 请尝试使其变得简单,因为我在 Python 编程方面非常非常缺乏经验!谢谢。
Basically I have an authlog/syslog file with a list of log in attempts and IP addresses - I need to make a Python program that will create a txt file with all the IP addresses that have more than 5 failed login attempts - a sort of "blacklist".
So basically something like:
if "uniqueipaddress" and "authentication failure" appear more than 5 times, add uniqueipaddress to txt file.
Any help would be greatly appreciated - please try and make it simple as I am very, very inexperienced in programming in Python! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于每一行:
然后查看字典:
Python 提示:
for line in open(filename)
split
方法,以及正则表达式ips[ip]
是尝试次数For each line:
Then go over the dictionary:
Python hints:
for line in open(filename)
split
method of a string, and regular expressionsips[ip]
is amount of attempts以下代码应该执行与您正在寻找的类似的操作。它并不完美,但它是一个很好的起点。
这假设您的日志文件的结构如下:
The following code should do something similar to what you're looking for. It's not perfect, but it's a good jumping off point.
This assumes that your log file is structured something like so: