From f1cbf96d972e9cc8065a901fe3aa5aea59fa2eec Mon Sep 17 00:00:00 2001 From: itsmostafa Date: Wed, 15 Nov 2023 12:08:14 -0800 Subject: [PATCH 1/3] fix: segments section --- src/navv/spreadsheet_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index 5e3555f..2f88dda 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -113,7 +113,7 @@ def get_segments_data(ws): ) all_ips = [] for segment in segments: - all_ips = all_ips + segment.network + all_ips.append(segment.network) if segment else None segments.append(all_ips) return segments From a6d62b8a440966b36560e80a87a8e91c2cc17b5d Mon Sep 17 00:00:00 2001 From: itsmostafa Date: Wed, 15 Nov 2023 13:27:40 -0800 Subject: [PATCH 2/3] fix: segments logic --- src/navv/data_types.py | 4 ---- src/navv/spreadsheet_tools.py | 32 ++++++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/navv/data_types.py b/src/navv/data_types.py index c48b69c..29aa4ca 100644 --- a/src/navv/data_types.py +++ b/src/navv/data_types.py @@ -20,12 +20,8 @@ class Segment: name: str description: str network: str - network_ips: list = field(init=False) color: str - def __post_init__(self): - self.network_ips = [str(ip) for ip in netaddr.IPNetwork(self.network)] - @dataclass class AnalysisRowItem: diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index 2f88dda..ac94aba 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -99,22 +99,26 @@ def get_inventory_data(ws, **kwargs): @timeit def get_segments_data(ws): - segments = list() + segments = [] + network_ip = "" for row in itertools.islice(ws.iter_rows(), 1, None): if not row[2].value: continue - segments.append( - data_types.Segment( - name=row[0].value, - description=row[1].value, - network=row[2].value, - color=[copy(row[0].fill), copy(row[0].font)], + network_ip = row[2].value + network_ips = [str(ip) for ip in netaddr.IPNetwork(network_ip)] + for ip in network_ips: + segments.append( + data_types.Segment( + name=row[0].value, + description=row[1].value, + network=ip, + color=[copy(row[0].fill), copy(row[0].font)], + ) ) - ) - all_ips = [] - for segment in segments: - all_ips.append(segment.network) if segment else None - segments.append(all_ips) + # all_ips = [] + # for segment in segments: + # all_ips = all_ips + segment.network_ips + # segments.append(all_ips) return segments @@ -268,7 +272,7 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs): This will capture the name description and the color coding identified within the worksheet. """ - # + segment_ips = [segment.network for segment in segments] if ip_to_check == str("0.0.0.0"): desc_to_change = ( "Unassigned IPv4", @@ -286,7 +290,7 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs): f"{'IPV6' if netaddr.valid_ipv6(ip_to_check) else 'IPV4'}{'_Multicast' if netaddr.IPAddress(ip_to_check).is_multicast() else ''}", IPV6_CELL_COLOR, ) - elif ip_to_check in segments[len(segments) - 1]: + elif ip_to_check in segment_ips: for segment in segments[:-1]: if ip_to_check not in segment.network: continue From 938cc47dce985c6d51a40326c4287ebba15ed6a7 Mon Sep 17 00:00:00 2001 From: itsmostafa Date: Wed, 15 Nov 2023 13:29:07 -0800 Subject: [PATCH 3/3] remove comments --- src/navv/spreadsheet_tools.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index ac94aba..9cd6bc1 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -115,10 +115,6 @@ def get_segments_data(ws): color=[copy(row[0].fill), copy(row[0].font)], ) ) - # all_ips = [] - # for segment in segments: - # all_ips = all_ips + segment.network_ips - # segments.append(all_ips) return segments