forked from savon-noir/python-libnmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreportjson.py
More file actions
22 lines (18 loc) · 739 Bytes
/
reportjson.py
File metadata and controls
22 lines (18 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
import json
from libnmap.objects import NmapHost, NmapService, NmapReport
from libnmap.parser import NmapParser
class ReportEncoder(json.JSONEncoder):
def default(self, obj):
otype = {'NmapHost': NmapHost,
'NmapOSFingerprint': NmapHost.NmapOSFingerprint,
'NmapService': NmapService,
'NmapReport': NmapReport}
if isinstance(obj, tuple(otype.values())):
key = '__%s__' % obj.__class__.__name__
return {key: obj.__dict__}
return json.JSONEncoder.default(self, obj)
class ReportDecoder(json.JSONDecoder):
def decode(self, json_str):
r = NmapParser.parse_fromdict(json.loads(json_str))
return r