
| Current Path : /home/ift/51_iftlib/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/ift/51_iftlib/blocked.py |
#!/usr/bin/python3
import os,re,sys
x = {}
y = {}
text = open("/etc/blocked.sh").read()
for zeile in os.popen("grep 'does not resolve' /var/log/mail.log"):
m = re.search(r"does not resolve.*?(\d+\.\d+\.\d+\.\d+)",zeile)
if m and not m.group(1) in text:
x['iptables -A INPUT -s ' + m.group(1) + ' -j DROP'] = 1
print(text)
for zeile in os.popen("grep 'Wrong password' /var/log/asterisk/messages"):
# print(zeile)
m = re.search(r"failed.*for.*?(\d+\.\d+\.\d+\.\d+).*Wrong",zeile)
# print(m.group(1))
# print(m and m.group(1) in text)
if m and (not m.group(1) in text):
# print(m.group(1))
o = 'iptables -A INPUT -s ' + m.group(1) + ' -j DROP'
if not o in y:
y[o] = 0
y[o] = y[o] + 1
#exit()
text1 = ""
for zeile in x.keys():
text = text + zeile + "\n"
text1 = text1 + zeile + "\n"
for o in y:
print(o)
if y[o] > 100:
text = text + o + "\n"
text1 = text1 + o + "\n"
print(text1)
open("/etc/blocked.sh","w").write(text)
open("/etc/blocked1.sh","w").write(text1)
os.system("sh /etc/blocked1.sh")