Skip to content

Commit

Permalink
Updated get_hostnames function to ignore comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
David-M-Berry committed May 28, 2024
1 parent 7c782e4 commit e2874da
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions samples/hosts/host_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down

0 comments on commit e2874da

Please sign in to comment.