Skip to content

Instantly share code, notes, and snippets.

@jgamblin

jgamblin/NVD.py

Last active Jul 26, 2019
Embed
What would you like to do?
NVD CVEs to Indivual JSON files
import requests
import json
import gzip
import os
import codecs
import time
from datetime import timedelta
start = time.time()
count = 0
baseURL = "https://nvd.nist.gov/feeds/json/cve/1.0/"
year = 2002
while year <= 2019:
yearstr = str(year)
os.mkdir(yearstr)
os.chdir(yearstr)
feed = ('nvdcve-1.0-'+yearstr+'.json.gz')
url = baseURL + feed
r = requests.get(url)
open(feed, 'wb').write(r.content)
with gzip.open(feed, 'rt', encoding="utf8") as fd:
data = json.load(fd)
for item in data['CVE_Items']:
if 'cve' in item:
if 'CVE_data_meta' in item['cve']:
if 'ID' in item['cve']['CVE_data_meta']:
count = count + 1
filename = (item['cve']['CVE_data_meta']['ID'] + '.json')
try:
with open(filename, 'wb') as f:
json.dump(item, codecs.getwriter('utf-8')(f),
ensure_ascii=False)
f.close()
except TypeError:
continue
os.chdir('..')
year = year + 1
elapsed = (time.time() - start)
print("CVEs Turned Into JSON Files:")
print(count)
print("Done In:")
print(str(timedelta(seconds=elapsed)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment