Skip to content

Commit 3d1f468

Browse files
authored
Merge pull request #52 from cisagov/fix/segments-section
fix: segments section
2 parents d159890 + 938cc47 commit 3d1f468

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/navv/data_types.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ class Segment:
2020
name: str
2121
description: str
2222
network: str
23-
network_ips: list = field(init=False)
2423
color: str
2524

26-
def __post_init__(self):
27-
self.network_ips = [str(ip) for ip in netaddr.IPNetwork(self.network)]
28-
2925

3026
@dataclass
3127
class AnalysisRowItem:

src/navv/spreadsheet_tools.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ def get_inventory_data(ws, **kwargs):
9999

100100
@timeit
101101
def get_segments_data(ws):
102-
segments = list()
102+
segments = []
103+
network_ip = ""
103104
for row in itertools.islice(ws.iter_rows(), 1, None):
104105
if not row[2].value:
105106
continue
106-
segments.append(
107-
data_types.Segment(
108-
name=row[0].value,
109-
description=row[1].value,
110-
network=row[2].value,
111-
color=[copy(row[0].fill), copy(row[0].font)],
107+
network_ip = row[2].value
108+
network_ips = [str(ip) for ip in netaddr.IPNetwork(network_ip)]
109+
for ip in network_ips:
110+
segments.append(
111+
data_types.Segment(
112+
name=row[0].value,
113+
description=row[1].value,
114+
network=ip,
115+
color=[copy(row[0].fill), copy(row[0].font)],
116+
)
112117
)
113-
)
114-
all_ips = []
115-
for segment in segments:
116-
all_ips = all_ips + segment.network
117-
segments.append(all_ips)
118118
return segments
119119

120120

@@ -268,7 +268,7 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs):
268268
269269
This will capture the name description and the color coding identified within the worksheet.
270270
"""
271-
#
271+
segment_ips = [segment.network for segment in segments]
272272
if ip_to_check == str("0.0.0.0"):
273273
desc_to_change = (
274274
"Unassigned IPv4",
@@ -286,7 +286,7 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs):
286286
f"{'IPV6' if netaddr.valid_ipv6(ip_to_check) else 'IPV4'}{'_Multicast' if netaddr.IPAddress(ip_to_check).is_multicast() else ''}",
287287
IPV6_CELL_COLOR,
288288
)
289-
elif ip_to_check in segments[len(segments) - 1]:
289+
elif ip_to_check in segment_ips:
290290
for segment in segments[:-1]:
291291
if ip_to_check not in segment.network:
292292
continue

0 commit comments

Comments
 (0)