misp-modules/misp_modules/modules/expansion/ipasn.py

40 lines
1.0 KiB
Python
Raw Normal View History

2016-05-01 12:09:33 +02:00
# -*- coding: utf-8 -*-
import json
from pyipasnhistory import IPASNHistory
2016-05-01 12:09:33 +02:00
misperrors = {'error': 'Error'}
mispattributes = {'input': ['ip-src', 'ip-dst'], 'output': ['freetext']}
moduleinfo = {'version': '0.1', 'author': 'Raphaël Vinot',
'description': 'Query an IP ASN history service (https://github.com/CIRCL/IP-ASN-history.git)',
'module-type': ['expansion', 'hover']}
def handler(q=False):
if q is False:
return False
request = json.loads(q)
if request.get('ip-src'):
toquery = request['ip-src']
elif request.get('ip-dst'):
toquery = request['ip-dst']
else:
misperrors['error'] = "Unsupported attributes type"
return misperrors
ipasn = IPASNHistory()
values = ipasn.query(toquery)
2016-05-04 12:52:01 +02:00
2016-05-01 12:09:33 +02:00
if not values:
misperrors['error'] = 'Unable to find the history of this IP'
return misperrors
return {'results': [{'types': mispattributes['output'], 'values': values}]}
def introspection():
return mispattributes
def version():
return moduleinfo