Skip to content

Commit f9c4f29

Browse files
committed
docs: updated README and snap install
Improve CLI network error handling and added Snap badges/install instructions.
1 parent b1b32a5 commit f9c4f29

2 files changed

Lines changed: 60 additions & 11 deletions

File tree

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11

22

33

4+
<h1 align="center">CVE Scanner CLI</h1>
5+
46
<div align="center">
5-
<img src="https://img.shields.io/github/last-commit/DebaA17/CVE-scanner-cli" height="40">
6-
<img src="https://img.shields.io/github/license/DebaA17/CVE-scanner-cli" height="40">
7-
<img src="https://img.shields.io/badge/python-3.7%2B-blue.svg" height="40">
8-
</div>
97

10-
# CVE Scanner CLI
8+
[![Snap Store](https://img.shields.io/badge/Snap-Store-82BEA0?logo=snapcraft&logoColor=white)](https://snapcraft.io/cvecli)
9+
[![CI Build](https://img.shields.io/github/actions/workflow/status/DebaA17/CVE-scanner-cli/snapstore.yml?label=build%20%26%20publish)](https://github.com/DebaA17/CVE-scanner-cli/actions/workflows/snapstore.yml)
10+
[![License](https://img.shields.io/github/license/DebaA17/CVE-scanner-cli)](https://github.com/DebaA17/CVE-scanner-cli/blob/main/LICENSE)
11+
12+
</div>
1113

1214
A command-line tool to search for CVEs (Common Vulnerabilities and Exposures) using public APIs. Results are displayed with color formatting and details using the rich library.
1315

@@ -22,6 +24,12 @@ A command-line tool to search for CVEs (Common Vulnerabilities and Exposures) us
2224
- requests
2325
- rich
2426

27+
## Installation (Snap Store)
28+
29+
```bash
30+
sudo snap install cvecli
31+
```
32+
2533
## Installation (Local/Global Usage)
2634
```bash
2735
git clone https://github.com/DebaA17/CVE-scanner-cli.git

cve_search_cli.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
BASE_URL = "https://cve.circl.lu/api"
1717
NVD_BASE_URL = "https://services.nvd.nist.gov/rest/json/cves/2.0"
1818

19+
REQUEST_TIMEOUT = (10, 30)
20+
session = requests.Session()
21+
session.headers.update(
22+
{
23+
"User-Agent": "cvecli (https://github.com/DebaA17/CVE-scanner-cli)",
24+
"Accept": "application/json",
25+
}
26+
)
27+
1928
def format_date(date_str):
2029
if not date_str:
2130
return "N/A"
@@ -26,9 +35,22 @@ def format_date(date_str):
2635

2736
def search_cve_by_id(cve_id):
2837
url = f"{BASE_URL}/cve/{cve_id}"
29-
resp = requests.get(url)
38+
try:
39+
resp = session.get(url, timeout=REQUEST_TIMEOUT)
40+
except requests.RequestException as exc:
41+
console.print(
42+
f"[bold red]Network error while fetching CVE data.[/]\n{exc}\n"
43+
"[dim]If you installed via Snap, ensure the 'network' plug is connected: "
44+
"'snap connections cvecli'.[/]"
45+
)
46+
return
47+
3048
if resp.status_code == 200:
31-
data = resp.json()
49+
try:
50+
data = resp.json()
51+
except ValueError:
52+
console.print("[bold red]Error: API returned invalid JSON.[/]")
53+
return
3254
cve_id = data.get('cveMetadata', {}).get('cveId', data.get('id'))
3355
published = format_date(data.get('cveMetadata', {}).get('datePublished', data.get('Published')))
3456
modified = format_date(data.get('cveMetadata', {}).get('dateUpdated', data.get('Modified')))
@@ -68,14 +90,31 @@ def search_cve_by_id(cve_id):
6890
for ref in references:
6991
panel_text.append(f" {ref}\n", style="blue underline")
7092
console.print(Panel(panel_text, title=f"{cve_id}", expand=False, border_style="red"))
93+
elif resp.status_code == 404:
94+
console.print(f"[bold red]Error: CVE {cve_id} not found.[/]")
7195
else:
72-
console.print(f"[bold red]Error: CVE {cve_id} not found.")
96+
console.print(
97+
f"[bold red]Error: Failed to fetch CVE {cve_id} (HTTP {resp.status_code}).[/]"
98+
)
7399

74100
def search_cve_by_keyword(keyword):
75101
params = {"keywordSearch": keyword, "resultsPerPage": 5}
76-
resp = requests.get(NVD_BASE_URL, params=params)
102+
try:
103+
resp = session.get(NVD_BASE_URL, params=params, timeout=REQUEST_TIMEOUT)
104+
except requests.RequestException as exc:
105+
console.print(
106+
f"[bold red]Network error while searching NVD.[/]\n{exc}\n"
107+
"[dim]If you installed via Snap, ensure the 'network' plug is connected: "
108+
"'snap connections cvecli'.[/]"
109+
)
110+
return
111+
77112
if resp.status_code == 200:
78-
data = resp.json()
113+
try:
114+
data = resp.json()
115+
except ValueError:
116+
console.print("[bold red]Error: NVD API returned invalid JSON.[/]")
117+
return
79118
results = data.get('vulnerabilities', [])
80119
if not results:
81120
console.print(f"[bold red]No CVEs found for keyword: {keyword}")
@@ -86,7 +125,9 @@ def search_cve_by_keyword(keyword):
86125
if cve_id:
87126
search_cve_by_id(cve_id)
88127
else:
89-
console.print(f"[bold red]Error: Could not fetch CVEs for keyword: {keyword}")
128+
console.print(
129+
f"[bold red]Error: Could not fetch CVEs for keyword '{keyword}' (HTTP {resp.status_code}).[/]"
130+
)
90131

91132
def interactive_menu():
92133
console.print("[bold green]\n==============================\n[bold yellow]Made by DEBASIS - CVE Checker CLI\n==============================\n", style="bold green")

0 commit comments

Comments
 (0)