def network_scanner(): """ The Function scans the network using the auxiliary functions above. :return: None """ start_time = time.perf_counter() print('Scanning your connections...\n') scan_suspicious_ports() finish_time = time.perf_counter() print( f'Network Scanning has finished in {progress_duration(finish_time - start_time)}' ) from Graphic_Interface import display_notifications display_notifications('Network Scanning process has finished.\n')
def update_software_version(): """ The Function updates the AntiVirus AV Software version. :return: None """ from AntiVirus_AV import latest_stored_version from Web_Scrapper import get_latest_software_version latest_version = get_latest_software_version() if latest_version != latest_stored_version: print( f'AntiVirus AV Update is available. Current Version: {latest_stored_version}. Latest Version: {latest_version}' ) print( 'Please visit https://AntiVirus-AV-Website.micha1245.repl.co and download the latest version.' ) else: print(f'You are up to date. Version: {latest_version}') from Graphic_Interface import display_notifications display_notifications('Updating process has finished.')
def check_for_updates(): """ The Function checks for updates by comparing the PC's version and build number to the latest ones. :return: None """ start_time = time.perf_counter() try: # Getting the current version and build usign platform module current_version = platform.release() current_build = platform.version()[platform.version().find('.', 4) + 1:] # Getting the newest version # checking for windows insider program build update latest_version, latest_build = Web_Scrapper.get_latest_windows_version( ) print(latest_version, latest_build) print(current_version, current_build) if current_version != latest_version or current_build != latest_build: print( f'There is new version of Windows that you can upgrade to. Version: {latest_version}:{latest_build} \n' ) update('Windows') else: print( f'Your Windows version is up to date. Version: Windows {latest_version}' ) print(f'Searching for drivers updates') update('Drivers') finish_time = time.perf_counter() print( f'Updating has finished in {progress_duration(finish_time - start_time)}' ) from Graphic_Interface import display_notifications display_notifications('Updating process has finished.') except Exception as e: print('Could not update')
def virus_scan(scan_type, path=ROOT): """ the function runs a the scan on the suspicious files that were founded if they were founded. :param scan_type: the type of the scan: quick or full :param path: the requested path to be quick scanned; default path ---> ROOT :return: None """ from Graphic_Interface import found_virus_screen global infected_files, failed_scanning scanned_extensions = dict() if not os.path.exists(path): # if the given path is not valid if path: print( f"""The given path: '{path}' is not valid. Please enter a new Path \n""" ) else: print('The given path was empty. Please enter a new Path \n') print("""Virus scan wasn't successfully completed.\n""") return # stopping the function print('Hold on. We are getting your files to be scanned.\n') with concurrent.futures.ThreadPoolExecutor() as executor: future = executor.submit(get_suspicious_files, scan_type, path) suspicious_files = future.result() start_time = time.perf_counter() # time counter starting if suspicious_files: # there are suspicious files to be scanned print(f'Starting to virus scan {path}') print(f'We are getting ready to scan {len(suspicious_files)} files\n') time.sleep(0.1) for index, file_path in enumerate(suspicious_files): # sending the file to deep scan threading.Thread(target=deep_scan, args=(file_path, )).start() if (index + 1) == len(suspicious_files): # printing for last file finish_time = time.perf_counter() # time counter finished sys.stdout.write( f'\rScanning ({index + 1} files || {int(((index + 1) / len(suspicious_files)) * 100)}%): {basename(file_path)} || {(progress_duration(finish_time - start_time))[:-2]}): {basename(file_path)}last' ) else: sys.stdout.write( f'\rScanning ({index + 1} files || {int(((index + 1) / len(suspicious_files)) * 100)}% || {(progress_duration(time.perf_counter() - start_time))[:-2]}): {basename(file_path)}' ) if infected_files: result = f'We found {len(infected_files)} infected files in Directory {path}.' else: result = f'Directory {path} is clean' for file_path in suspicious_files: # getting scanned file's extensions statistics file_extension = Path(file_path).suffix if file_path not in failed_scanning: if file_extension not in scanned_extensions: scanned_extensions[file_extension] = 1 else: scanned_extensions[file_extension] += 1 print('\n\nVirus Scan Report:') print(result) print( f'Successfully scanned: {len(suspicious_files) - len(failed_scanning)} ' f'out of {len(suspicious_files)} Files || Failed to scan : ' f'{len(failed_scanning)} files') [ print( f'{"%.2f" % float((value / (len(suspicious_files) - len(failed_scanning))) * 100)}% ({value}) {extension} files' ) for extension, value in scanned_extensions.items() ] # printing scanned file's extensions statistics print(f'Virus Scan has finished in ' f'{progress_duration(finish_time - start_time)}') if infected_files: # displaying found viruses screen found_virus_screen(infected_files) from Graphic_Interface import display_notifications display_notifications('Virus Scanning process has finished.') else: print( f'We did not ran virus scan in {path} since there are not suspicious files there.\n' )
def shred(mode='Basic', path=''): """ The Function shreds files in order to protect the user's identity. :param mode: the shredding mode: Basic, Safe, Complete :param path: the path to be shredded: Recycle Bin or Temporary files :return: None """ start_time = time.perf_counter() failed_shredding = list() if mode == 'Basic': repeat = 1 elif mode == 'Safe': repeat = 5 else: # mode == 'Complete': repeat = 10 if path == 'Let Me Choose': path = random.choice(['Recycle Bin', 'Temporary Files']) executed = False # An auxiliary boolean variable if path == 'Recycle Bin': object_list = list(winshell.recycle_bin()) if object_list: # if list is not empty print(f'Starting Shredding process at {path}\n') executed = True print(f'We are getting ready to shred {len(object_list)} files') time.sleep(1) for index, file_path in enumerate(object_list): for _ in range(repeat): try: success = False file_path = '\\'.join( file_path.original_filename().split('\\') ) # adding double slash (\\) in the file_path # undeleting the selected file winshell.undelete(file_path.original_filename()) if not os.path.isdir(file_path): # is file success = shred_file(file_path) if not success: # if didn't succeed shredding the file failed_shredding.append(file_path) # deleting the selected file again winshell.delete_file(file_path.original_filename()) except: pass if (index + 1) == (len(object_list)): # last file sys.stdout.write( f'\rShredding ({int(((index + 1) / len(object_list)) * 100)}%): {basename(file_path)}last' ) else: sys.stdout.write( f'\rShredding ({int(((index + 1) / len(object_list)) * 100)}%): {basename(file_path)}' ) # Emptying recycle bin. winshell.recycle_bin().empty(confirm=False, show_progress=False, sound=False) print('\nShredding Report:') print( f'Successfully shred: {len(object_list) - len(failed_shredding)} ' f'out of {len(object_list)} Files || Failed to shred : ' f'{len(failed_shredding)} files') finish_time = time.perf_counter() else: print('There are no items in the Recycle Bin to be shredded\n') elif path == 'Temporary Files': directory_path = r'c:\windows\temp' object_list = os.listdir(directory_path) files_list = [] if object_list: while object_list: for file in object_list: file_path = directory_path + file if file_path not in files_list: files_list.append(file_path) object_list.remove(file) print(f'Starting Shredding process at {path}\n') executed = True print(f'We are getting ready to shred {len(files_list)} files') time.sleep(1) for index, file_path in enumerate(files_list): if (index + 1) == len(object_list): # last file sys.stdout.write( f'\rShredding ({int((index / len(files_list)) * 100)}%): {basename(file_path)}last' ) else: sys.stdout.write( f'\rShredding ({int((index / len(files_list)) * 100)}%): {basename(file_path)}' ) for _ in range(repeat): try: if not os.path.isdir(file_path): # is file success = shred_file(file_path) if not success: # if didn't succeed shredding the file failed_shredding.append(file_path) except: pass for file in files_list: os.remove(file) process = subprocess.Popen( 'del /S /Q /F %s\\*.*' % directory_path, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # deleting all temporary files process.communicate() finish_time = time.perf_counter() print('\n\nShredding Report:') print( f'Successfully shredded: {len(files_list) - len(failed_shredding)} ' f'out of {len(files_list)} Files || Failed to shred : ' f'{len(failed_shredding)} files. Deleted: {len(files_list)}') if executed: print( f'Shredding has been finished in {progress_duration(finish_time - start_time)}' ) from Graphic_Interface import display_notifications display_notifications('Shredding process has finished.') else: print( f"""We didn't shred any files since we couldn't find any in {path} """ )