Skip to content

Commit e230e0a

Browse files
committed
Create vuldb_api_demo.py
1 parent 72c3b84 commit e230e0a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

vuldb_api_demo.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
vuldb_api_demo - Python VulDB API Demo
5+
6+
License: GPL-3.0
7+
Required Dependencies: requests, argparse, json
8+
Optional Dependencies: None
9+
'''
10+
11+
import requests
12+
import argparse
13+
import json
14+
15+
# Define arguments for API script
16+
parser = argparse.ArgumentParser()
17+
parser.add_argument('--recent', dest='recent', default=5, type=int, help='It is possible to show the most recent entries with the request method recent. The method itself demands a number of entries which shall be shown.')
18+
parser.add_argument('--details', dest='details', default=0, type=int, help='The field details is 0 or 1 and declares if the results are basic or detailed. This difference influences the API credit consumption.')
19+
parser.add_argument('--id', dest='id', help='It is very simple to request the details for a vulnerability entry. The argument demands a VulDB Id.')
20+
args = parser.parse_args()
21+
22+
# Add your personal API key here
23+
personalApiKey = ''
24+
25+
# Set HTTP Header
26+
userAgent = 'VulDB API Advanced Python Demo Agent'
27+
headers = {'User-Agent': userAgent, 'X-VulDB-ApiKey': personalApiKey}
28+
29+
# URL VulDB endpoint
30+
url = 'https://vuldb.com/?api'
31+
32+
# Choose the API call based on the passed arguments
33+
# Default call is the last 5 recent entries
34+
if args.recent is not None:
35+
postData = {'recent': int(args.recent)}
36+
elif args.id is not None:
37+
postData = {'id': int(args.id)}
38+
else:
39+
postData = {'recent': 5}
40+
41+
if args.details is not None:
42+
postData['details'] = int(args.details)
43+
44+
# Get API response
45+
response = requests.post(url,headers=headers,data=postData)
46+
47+
# Display result if evertything went OK
48+
if response.status_code == 200:
49+
50+
# Parse HTTP body as JSON
51+
responseJson = json.loads(response.content)
52+
53+
# Output
54+
for i in responseJson['result']:
55+
print(i['entry'])
56+
#print(i["entry"]["id"])
57+
#print(i["entry"]["title"])

0 commit comments

Comments
 (0)