Update main.py

This commit is contained in:
Sam Sneed 2024-07-24 16:51:31 -05:00 committed by GitHub
parent 57491d025a
commit a2bf651d94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

12
main.py
View file

@ -12,6 +12,7 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from pathlib import Path
import requests
import certifi
import getpass
import tensorflow as tf # TensorFlow for GPU monitoring
import re # Regular expressions for address detection
@ -97,9 +98,18 @@ class SuspiciousFileHandler(FileSystemEventHandler):
def get_file_owner(file_path):
try:
# On Windows, use the current users name
if os.name == 'nt':
import win32security
sd = win32security.GetFileSecurity(file_path, win32security.OWNER_SECURITY_INFORMATION)
owner_sid = sd.GetSecurityDescriptorOwner()
return win32security.LookupAccountSid(None, owner_sid)[0]
owner, _ = win32security.LookupAccountSid(None, owner_sid)
return owner
else:
# On Unix-like systems, use the owner of the file
import pwd
file_stat = os.stat(file_path)
return pwd.getpwuid(file_stat.st_uid).pw_name
except Exception as e:
print(f"Error getting file owner: {e}")
return "Unknown"