Skip to content

Commit 303f010

Browse files
committed
add dnsbl-query to api
1 parent c52a35a commit 303f010

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
3+
summary: 'Query IP in Risk-Database DNS-BL'
4+
5+
parameters:
6+
- in: 'path'
7+
name: 'ip'
8+
description: 'IP to query'
9+
type: 'string'
10+
11+
definitions:
12+
IPStatus:
13+
type: 'object'
14+
properties:
15+
listed:
16+
type: 'boolean'
17+
description: 'If the IP is listed in the DNS-BL'
18+
category:
19+
type: 'string'
20+
description: 'The category the IP for which the IP was reported as'
21+
required: ['listed', 'category']
22+
23+
ErrorMsg:
24+
type: 'object'
25+
properties:
26+
msg:
27+
type: 'string'
28+
description: 'Error Message'
29+
30+
responses:
31+
200:
32+
description: 'Risk-Database DNS-BL status of the IP'
33+
schema:
34+
$ref: '#/definitions/IPStatus'
35+
400:
36+
description: 'Invalid IP provided'
37+
schema:
38+
$ref: '#/definitions/ErrorMsg'

src/riskdb/api/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from flasgger import swag_from, Swagger
2222
from flask import Flask, request, Response, json, redirect
2323
from oxl_utils.valid.net import valid_public_ip, valid_asn, get_ipv
24+
from dnsbl_check import CheckIP
25+
from dnsbl_check.provider_config import CUSTOM_PROVIDERS
2426

2527
from riskdb.users import USER_TOKENS
2628
from riskdb.config import BUILD_DIR, KIND_FILES, REPORT_DIR, RISK_CATEGORIES, NET_SIZE, \
@@ -225,6 +227,23 @@ def list_asn_kind(kind: str) -> Response:
225227
return _response_json(code=200, data={'asn': ASN_KIND_DATA[kind]})
226228

227229

230+
@app.route('/api/dnsbl/ip/<ip>', methods=['GET'])
231+
@swag_from('apidocs/check_dnsbl_ip.yml')
232+
def check_dnsbl_ip(ip) -> Response:
233+
if not valid_public_ip(ip):
234+
return _response_json(code=400, data={'msg': 'Invalid IP provided'})
235+
236+
provider = CUSTOM_PROVIDERS['ip.dnsbl.risk.oxl.app']()
237+
238+
with CheckIP(providers=[provider]) as checker:
239+
result = checker.check(ip).to_dict()
240+
241+
return _response_json(code=200, data={
242+
'listed': result['detected'],
243+
'category': None if len(result['categories']) == 0 else result['categories'][0],
244+
})
245+
246+
228247
@app.route('/')
229248
def catch_base():
230249
return redirect('/api/docs/', code=302)

src/riskdb/api/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ flask
22
waitress
33
maxminddb
44
oxl-utils
5-
flasgger
5+
flasgger
6+
dnsbl-check

0 commit comments

Comments
 (0)