Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from concurrent.futures import ThreadPoolExecutor;
- import socket;
- import time;
- import re;
- # /home/a221251782/Monitoramento/
- BACKUPFILEPATH = 'log-backup.log';
- THREATCOOLDOWN = 10.0;
- THREATREGEX = re.compile(r'(\d)\1{1,3}');
- SERVERHOST = 'localhost';
- SERVERPORT = 8191;
- MAXWORKERS = 4;
- def probeline(ln):
- if THREATREGEX.search(ln):
- MESSAGE = 'User - 221251782 - Possível Ameaça!';
- print(MESSAGE);
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sc:
- SERVERTUPLE = (SERVERHOST, SERVERPORT);
- sc.connect(SERVERTUPLE);
- sc.sendall(MESSAGE.encode());
- #with:
- #if:
- #def:
- def monitorthreats():
- seenlines = 0;
- tpexec = ThreadPoolExecutor(max_workers=MAXWORKERS);
- while True:
- with open(BACKUPFILEPATH, 'r') as fh:
- rlines = fh.readlines();
- #with:
- if seenlines < len(rlines):
- newlines = rlines[seenlines:];
- for ln in newlines:
- tpexec.submit(probeline, ln);
- #for:
- seenlines = len(rlines);
- #if:
- time.sleep(THREATCOOLDOWN);
- #while:
- #def:
- if __name__ == '__main__': monitorthreats();
Advertisement
Add Comment
Please, Sign In to add comment