import re import glob # Define the pattern to search for pattern = r':8443|login_up.php|\/smb\/' # Define the pattern to exclude exclude_pattern = r'cpsess|email_account|addon|masterweb|UNKNOWN|null|telnet|fakepassword|sql|pops' # Find all.txt files in the current directory txt_files = glob.glob('*.txt') # Open the result file in append mode with open('ssh.txt', 'a', encoding='utf-8') as result_file: for file in txt_files: with open(file, 'r', encoding='utf-8', errors='ignore') as f: for num, line in enumerate(f, 1): if re.search(pattern, line) and not re.search(exclude_pattern, line, re.IGNORECASE): result_file.write(f"{line.strip()}\n")