ViniCastilho

cdp-b2-t1-analise-ameacas.py

Jun 28th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. from concurrent.futures import ThreadPoolExecutor;
  2. import socket;
  3. import time;
  4. import re;
  5.  
  6. # /home/a221251782/Monitoramento/
  7. BACKUPFILEPATH = 'log-backup.log';
  8. THREATCOOLDOWN = 10.0;
  9. THREATREGEX = re.compile(r'(\d)\1{1,3}');
  10. SERVERHOST = 'localhost';
  11. SERVERPORT = 8191;
  12. MAXWORKERS = 4;
  13.  
  14. def probeline(ln):
  15. if THREATREGEX.search(ln):
  16. MESSAGE = 'User - 221251782 - Possível Ameaça!';
  17. print(MESSAGE);
  18. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sc:
  19. SERVERTUPLE = (SERVERHOST, SERVERPORT);
  20. sc.connect(SERVERTUPLE);
  21. sc.sendall(MESSAGE.encode());
  22. #with:
  23. #if:
  24. #def:
  25.  
  26. def monitorthreats():
  27. seenlines = 0;
  28. tpexec = ThreadPoolExecutor(max_workers=MAXWORKERS);
  29. while True:
  30. with open(BACKUPFILEPATH, 'r') as fh:
  31. rlines = fh.readlines();
  32. #with:
  33. if seenlines < len(rlines):
  34. newlines = rlines[seenlines:];
  35. for ln in newlines:
  36. tpexec.submit(probeline, ln);
  37. #for:
  38. seenlines = len(rlines);
  39. #if:
  40. time.sleep(THREATCOOLDOWN);
  41. #while:
  42. #def:
  43.  
  44. if __name__ == '__main__': monitorthreats();
  45.  
Advertisement
Add Comment
Please, Sign In to add comment