Skip to content

Commit 23e6df3

Browse files
committed
dupe stout
1 parent 609b0d1 commit 23e6df3

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

HostCount.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ def main():
6868
grand_total_hosts.update(file_hosts)
6969
print(f"\nTotal unique hosts across all files: {len(grand_total_hosts)}")
7070

71+
# Build host -> set(files) mapping once for both -D output and the duplicate note
72+
host_to_files = defaultdict(set)
73+
for fname, hosts in file_hosts_map.items():
74+
for h in hosts:
75+
host_to_files[h].add(fname)
76+
duplicates_map = {host: sorted(list(files)) for host, files in host_to_files.items() if len(files) > 1}
77+
duplicate_count = len(duplicates_map)
78+
79+
# If -D not used, but duplicates exist, print a concise note that duplicates were found and are only counted once
80+
if not args.duplicates and duplicate_count > 0:
81+
print(f"\nNote: {duplicate_count} host(s) were found in more than one file but are only counted once in the total unique host count. Use -D to list them.")
82+
7183
if args.rfc1918:
7284
print("\nRFC1918 breakdown per file:")
7385
for fname in sorted(file_hosts_map.keys()):
@@ -81,21 +93,13 @@ def main():
8193
print(f"\nTotals across all files: {total_rfc} RFC1918, {total_non_rfc} non-RFC1918")
8294

8395
if args.duplicates:
84-
# Build host -> set(files) mapping
85-
host_to_files = defaultdict(set)
86-
for fname, hosts in file_hosts_map.items():
87-
for h in hosts:
88-
host_to_files[h].add(fname)
89-
90-
# Find hosts present in more than one file
91-
duplicates = {host: sorted(list(files)) for host, files in host_to_files.items() if len(files) > 1}
92-
93-
if not duplicates:
96+
# Use the mapping we already built to list duplicates
97+
if not duplicates_map:
9498
print("\nNo duplicate hosts found between files.")
9599
else:
96-
print(f"\nDuplicate hosts found between files: {len(duplicates)} hosts\n")
97-
for host in sorted(duplicates.keys(), key=lambda x: tuple(int(p) for p in x.split('.'))):
98-
files_list = ", ".join(duplicates[host])
100+
print(f"\nDuplicate hosts found between files: {len(duplicates_map)} hosts\n")
101+
for host in sorted(duplicates_map.keys(), key=lambda x: tuple(int(p) for p in x.split('.'))):
102+
files_list = ", ".join(duplicates_map[host])
99103
print(f"{host}: {files_list}")
100104

101105
elif args.file:

0 commit comments

Comments
 (0)