File: es_plugin.py

package info (click to toggle)
python-libnmap 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,416 kB
  • sloc: xml: 5,572; python: 4,299; makefile: 149
file content (18 lines) | stat: -rw-r--r-- 554 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3

import json
from datetime import datetime

from libnmap.parser import NmapParser
from libnmap.plugins.es import NmapElasticsearchPlugin
from libnmap.reportjson import ReportDecoder

nmap_report = NmapParser.parse_fromfile("libnmap/test/files/1_hosts.xml")
mindex = datetime.fromtimestamp(nmap_report.started).strftime("%Y-%m-%d")
db = NmapElasticsearchPlugin(index=mindex)
dbid = db.insert(nmap_report)
nmap_json = db.get(dbid)

nmap_obj = json.loads(json.dumps(nmap_json), cls=ReportDecoder)
print(nmap_obj)
# print(db.getall())