From 338728cddb254e9c01b575d5e707f5f4fb06140c Mon Sep 17 00:00:00 2001 From: Donovan Nichols Date: Fri, 17 Nov 2023 14:59:54 -0700 Subject: [PATCH 1/2] Update spreadsheet_tools.py to address error with desc_to_change variable. Bump version to 3.3.1 --- .idea/misc.xml | 3 ++ ...chitecture-verification-and-validation.iml | 4 +- src/navv/_version.py | 2 +- src/navv/spreadsheet_tools.py | 43 +++++++++++-------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 0172830..98acd46 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/.idea/network-architecture-verification-and-validation.iml b/.idea/network-architecture-verification-and-validation.iml index befceda..f6fdecd 100644 --- a/.idea/network-architecture-verification-and-validation.iml +++ b/.idea/network-architecture-verification-and-validation.iml @@ -2,9 +2,11 @@ + + - + diff --git a/src/navv/_version.py b/src/navv/_version.py index a3fa2e1..fa7e08b 100644 --- a/src/navv/_version.py +++ b/src/navv/_version.py @@ -1,2 +1,2 @@ """This file defines the version of this module.""" -__version__ = "3.3.1" +__version__ = "3.3.2" diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index 29ac0d8..6ba7c97 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -93,6 +93,8 @@ def get_inventory_data(ws, **kwargs): ip=row[0].value, name=row[1].value, color=(copy(row[0].fill), copy(row[0].font)), + mac_address="", + vendor="" ) return inventory @@ -269,7 +271,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] - desc_to_change = ("Unknown IP Address", IPV6_CELL_COLOR) + desc_to_change = ("Not Triggered IP", IPV6_CELL_COLOR) if ip_to_check == str("0.0.0.0"): desc_to_change = ( "Unassigned IPv4", @@ -288,39 +290,46 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs): IPV6_CELL_COLOR, ) elif ip_to_check in segment_ips: - for segment in segments[:-1]: - if ip_to_check not in segment.network: - continue - elif ip_to_check in dns_data: - desc_to_change = (dns_data[ip_to_check] , segment.color) - elif ip_to_check in inventory: - desc_to_change = (inventory[ip_to_check].name, segment.color) - else: + for x in range(0, len(segments[:-1])): + if segments[x].network == ip_to_check: + if ip_to_check in dns_data: + resolution = dns_data[ip_to_check].name + elif ip_to_check in inventory: + resolution = inventory[ip_to_check].name + else: + resolution = f"Unknown device in {segments[x].name} network" + unk_int_IPs.add(ip_to_check) + if not netaddr.IPAddress(ip_to_check).is_private(): + resolution = resolution + " {Non-Priv IP}" desc_to_change = ( - f"Unknown device in {segment.name} network", - segment.color, - ) - unk_int_IPs.add(ip_to_check) - elif ip_to_check in inventory: - desc_to_change = (inventory[ip_to_check].name, inventory[ip_to_check].color) + resolution, + segments[x].color, + ) + + # elif ip_to_check in inventory: + # desc_to_change = (inventory[ip_to_check].name, inventory[ip_to_check].color) + elif netaddr.IPAddress(ip_to_check).is_private(): if ip_to_check in dns_data: desc_to_change = (dns_data[ip_to_check], INTERNAL_NETWORK_CELL_COLOR) + elif ip_to_check in inventory: + desc_to_change = (inventory[ip_to_check].name, INTERNAL_NETWORK_CELL_COLOR) else: desc_to_change = ("Unknown Internal address", INTERNAL_NETWORK_CELL_COLOR) unk_int_IPs.add(ip_to_check) else: ext_IPs.add(ip_to_check) - resolution = "Unresolved external address" if ip_to_check in dns_data: resolution = dns_data[ip_to_check] + elif ip_to_check in inventory: + resolution = inventory[ip_to_check].name + " {Non-Priv IP}" else: try: resolution = socket.gethostbyaddr(ip_to_check)[0] except socket.herror: ALREADY_UNRESOLVED.append(ip_to_check) finally: - dns_data[ip_to_check] = resolution + resolution = "Unresolved external address" desc_to_change = (resolution, EXTERNAL_NETWORK_CELL_COLOR) return desc_to_change From d2a81436295f0fbb8dbb19e744ecc1c38b44e0a7 Mon Sep 17 00:00:00 2001 From: Donovan Nichols Date: Fri, 17 Nov 2023 15:07:31 -0700 Subject: [PATCH 2/2] Fixed script that adds metadata to each IP address within spreadsheet_tools.py. Improved logic and decision points. Fixed error in default values for inventory that didn't have a assigned vendor or mac address. Bumped version to 3.3.2. --- src/navv/spreadsheet_tools.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index 6ba7c97..cf72d93 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -264,9 +264,12 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs): * DHCP Broadcasting * Multicast * Within Segments identified - * Within Inventory, not within an Identified Segment + * Resolution by DNS, then Inventory, and then Unknown + * Appends name if External IP * Private Network + * Resolution by DNS, Inventory, then Unknown * External (Public IP space) or Internet + * Resolution by DNS, Unknown This will capture the name description and the color coding identified within the worksheet. """ @@ -305,10 +308,6 @@ def handle_ip(ip_to_check, dns_data, inventory, segments, ext_IPs, unk_int_IPs): resolution, segments[x].color, ) - - # elif ip_to_check in inventory: - # desc_to_change = (inventory[ip_to_check].name, inventory[ip_to_check].color) - elif netaddr.IPAddress(ip_to_check).is_private(): if ip_to_check in dns_data: desc_to_change = (dns_data[ip_to_check], INTERNAL_NETWORK_CELL_COLOR)