Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- import requests
- api_key = "<api key here>"
- s = requests.Session()
- def nvd_call(**args):
- headers = {
- "apiKey": api_key
- }
- return s.get("https://services.nvd.nist.gov/rest/json/cves/2.0", headers=headers, params=args)
- def dump_latest():
- r = nvd_call(lastModStartDate="2023-01-05T16:52:31.173", lastModEndDate="2023-01-05T17:52:31.173")
- r.raise_for_status()
- print(r.json())
- def dump_all():
- def fetcher():
- index = 0
- while True:
- r = nvd_call(startIndex=index)
- r.raise_for_status()
- data = r.json()
- index = data["startIndex"]
- total = data["totalResults"]
- per_page = data["resultsPerPage"]
- for cve in data["vulnerabilities"]:
- yield cve
- index += per_page
- if index >= total:
- break
- # TODO recommended to sleep for 6 seconds
- for cve in fetcher():
- print(cve["cve"]["id"])
- if __name__ == "__main__":
- dump_all()
Advertisement
Add Comment
Please, Sign In to add comment