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
30 lines (25 loc) · 1.03 KB
/
reportjson.py
File metadata and controls
30 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from libnmap.objects import NmapHost, NmapService, NmapReport
from libnmap.objects.os import NmapOSFingerprint, NmapOSMatch, NmapOSClass
from libnmap.objects.os import CPE, OSFPPortUsed
from libnmap.parser import NmapParser
class ReportEncoder(json.JSONEncoder):
def default(self, obj):
otype = {'NmapHost': NmapHost,
'NmapOSFingerprint': NmapOSFingerprint,
'NmapOSMatch': NmapOSMatch,
'NmapOSClass': NmapOSClass,
'CPE': CPE,
'OSFPPortUsed': OSFPPortUsed,
'NmapService': NmapService,
'NmapReport': NmapReport}
if isinstance(obj, tuple(otype.values())):
key = ('__{0}__').format(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