2019-07-05 14:26:25 +00:00
|
|
|
from core.prototypes.AbstractStorage import AbstractStorage
|
2019-03-23 22:02:55 +00:00
|
|
|
import json
|
|
|
|
from threading import RLock
|
|
|
|
|
|
|
|
class JSONStorage(AbstractStorage):
|
|
|
|
|
|
|
|
def __init__(self, path):
|
|
|
|
self.path = path
|
|
|
|
self.respdict = dict()
|
|
|
|
self.lock = RLock()
|
|
|
|
|
2019-07-05 14:26:25 +00:00
|
|
|
def put_responce(self, ip:'ipv4_str', port:'port', scan_result:'scan_result'):
|
2019-03-23 22:02:55 +00:00
|
|
|
if ip not in self.respdict.keys():
|
|
|
|
self.respdict[ip] = {"open": [], "close": []}
|
2019-07-05 14:26:25 +00:00
|
|
|
self.respdict[ip]["open" if scan_result == 0
|
|
|
|
else "close"].append(port)
|
2019-03-23 22:02:55 +00:00
|
|
|
|
|
|
|
def save(self):
|
|
|
|
print("saving")
|
|
|
|
with open(self.path, "w") as f:
|
|
|
|
json.dump(self.respdict, f)
|
|
|
|
self.respdict = {}
|