Skip to content

Commit

Permalink
Merge pull request #80 from lamusmaser/master
Browse files Browse the repository at this point in the history
notScannedSince now goes through full report, instead of just the first page
  • Loading branch information
paragbaxi committed Feb 14, 2020
2 parents 8553876 + 373672a commit ac3ff38
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions qualysapi/api_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from urllib import parse as urlparse

from lxml import objectify

Expand Down Expand Up @@ -187,29 +188,40 @@ def listReports(self, id=0):
def notScannedSince(self, days):
call = "/api/2.0/fo/asset/host/"
parameters = {"action": "list", "details": "All"}
hostData = objectify.fromstring(self.request(call, parameters).encode("utf-8"))
hostArray = []
today = datetime.date.today()
for host in hostData.RESPONSE.HOST_LIST.HOST:
if host.find("LAST_VULN_SCAN_DATETIME"):
last_scan = str(host.LAST_VULN_SCAN_DATETIME).split("T")[0]
last_scan = datetime.date(
int(last_scan.split("-")[0]),
int(last_scan.split("-")[1]),
int(last_scan.split("-")[2]),
)
if (today - last_scan).days >= days:
hostArray.append(
Host(
host.find("DNS"),
host.find("ID"),
host.find("IP"),
host.find("LAST_VULN_SCAN_DATETIME"),
host.find("NETBIOS"),
host.find("OS"),
host.find("TRACKING_METHOD"),
hasNextPage = True
while hasNextPage:
hostData = objectify.fromstring(self.request(call, parameters).encode("utf-8"))
for host in hostData.RESPONSE.HOST_LIST.HOST:
if host.find("LAST_VULN_SCAN_DATETIME"):
last_scan = str(host.LAST_VULN_SCAN_DATETIME).split("T")[0]
last_scan = datetime.date(
int(last_scan.split("-")[0]),
int(last_scan.split("-")[1]),
int(last_scan.split("-")[2]),
)
if (today - last_scan).days >= days:
hostArray.append(
Host(
host.find("DNS"),
host.find("ID"),
host.find("IP"),
host.find("LAST_VULN_SCAN_DATETIME"),
host.find("NETBIOS"),
host.find("OS"),
host.find("TRACKING_METHOD"),
)
)
try:
id_min = dict(
urlparse.parse_qsl(
urlparse.urlparse(str(hostData.RESPONSE.WARNING.URL)).query
)
)["id_min"]
parameters["id_min"] = id_min
except:
hasNextPage = False

return hostArray

Expand Down

0 comments on commit ac3ff38

Please sign in to comment.