From e2874dae38ebc397ce72be510a7342cacb163fed Mon Sep 17 00:00:00 2001 From: David-M-Berry <168669748+David-M-Berry@users.noreply.github.com> Date: Tue, 28 May 2024 10:05:06 -0700 Subject: [PATCH] Updated get_hostnames function to ignore comments. --- samples/hosts/host_search.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/samples/hosts/host_search.py b/samples/hosts/host_search.py index e433a1d88..53db06654 100755 --- a/samples/hosts/host_search.py +++ b/samples/hosts/host_search.py @@ -66,12 +66,16 @@ def consume_arguments() -> Namespace: def get_hostnames(target_file: str): - """Open CSV and import serials.""" + """Open file and import hostnames, ignoring comments.""" try: - with open(target_file, newline='') as host_file: + with open(target_file, 'r') as host_file: print("Opening hostname file") - return host_file.read().splitlines() - + hostnames = [] + for line in host_file: + line = line.split('#')[0].strip() # Remove comments and strip whitespace + if line: # Ignore empty lines + hostnames.append(line) + return hostnames except FileNotFoundError: raise SystemExit( "You must provide a valid hostname file with the '-f' argument, "