blob: b3861550d1ca7364ffd2cecf73fdfb9b4ebd7e13 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
"""Basic usage examples for nvdb-py."""
import asyncio
from nvd import NVDClient
async def main() -> None:
"""Run basic examples."""
async with NVDClient() as client:
print("=" * 80)
print("Example 1: Get a specific CVE")
print("=" * 80)
cve = await client.cve.get_cve("CVE-2021-44228")
print(f"CVE ID: {cve.id}")
print(f"Published: {cve.published}")
print(f"Status: {cve.vulnStatus}")
print(f"CVSS v3 Score: {cve.cvss_v3_score}")
print(f"Description: {cve.description[:200]}...")
print()
print("=" * 80)
print("Example 2: Search CVEs by keyword (limited to 5 results)")
print("=" * 80)
count = 0
async for cve in client.cve.search_cves(keyword="sql injection"):
print(f"{cve.id}: {cve.description[:100]}...")
count += 1
if count >= 5:
break
print()
print("=" * 80)
print("Example 3: Get CVEs with CRITICAL severity (limited to 5)")
print("=" * 80)
count = 0
async for cve in client.cve.search_cves(cvss_v3_severity="CRITICAL"):
score = cve.cvss_v3_score or "N/A"
print(f"{cve.id} - Score: {score} - {cve.description[:80]}...")
count += 1
if count >= 5:
break
print()
print("=" * 80)
print("Example 4: Search CPEs by keyword")
print("=" * 80)
count = 0
async for cpe in client.cpe.search_cpes(keyword="apache"):
print(f"{cpe.cpeName}")
print(f" Title: {cpe.title}")
print(f" Deprecated: {cpe.deprecated}")
count += 1
if count >= 5:
break
print()
print("=" * 80)
print("Example 5: Get CVE change history")
print("=" * 80)
history = await client.history.get_cve_history("CVE-2021-44228")
print(f"Found {len(history)} change events for CVE-2021-44228")
for change in history[:3]:
print(f" {change.eventName} at {change.created}")
print()
if __name__ == "__main__":
asyncio.run(main())
|