Skip to content

Commit

Permalink
Change Exception types
Browse files Browse the repository at this point in the history
  • Loading branch information
LindseyDurst committed May 31, 2023
1 parent 4e3fc74 commit 1dd51d3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions serveradmin/nessus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging
import requests
import certifi
from ipaddress import IPv4Address, IPv4Network, ip_address, ip_network
from ipaddress import IPv4Address, IPv4Network, ip_address, ip_network, AddressValueError

ca_certificates = certifi.where()

Expand Down Expand Up @@ -175,7 +175,7 @@ def request(self, url, data=None, method='POST', download=False, json_output=Fal
try:
response = getattr(self.session, method)(url, data=data, verify=ca_certificates)
break
except Exception as e:
except requests.RequestException as e:
self.logger.error("[!] [CONNECTION ERROR] - Run into connection issue: %s" % (e))
self.logger.error("[!] Retrying in 10 seconds")
time.sleep(10)
Expand All @@ -191,7 +191,7 @@ def request(self, url, data=None, method='POST', download=False, json_output=Fal
continue
self.login()
self.logger.info('Session token refreshed')
except Exception as e:
except requests.RequestException as e:
self.logger.error('Could not refresh session token. Reason: %s' % (str(e)))
else:
success = True
Expand Down Expand Up @@ -265,15 +265,19 @@ def check_if_running(self, new_targets):
for new_target in new_targets:
try:
ip = IPv4Address(existing_target)
except Exception:
except AddressValueError:
network = IPv4Network(existing_target)

if ip and ip_address(new_target) and ip == new_target:
scan_ids.add(str(scan['scan_id']))
elif network and ip_address(new_target) and new_target in network:
scan_ids.add(str(scan['scan_id']))
elif network and ip_network(new_target) and network.overlaps(new_target):
scan_ids.add(str(scan['scan_id']))
else:
try:
if network and ip_network(new_target) and network.overlaps(new_target):
scan_ids.add(str(scan['scan_id']))
except TypeError:
continue
scan_ids = list(scan_ids)
return scan_ids

Expand Down

0 comments on commit 1dd51d3

Please sign in to comment.