mirror of
https://github.com/ChronosX88/PyNesca.git
synced 2024-11-22 05:02:18 +00:00
Added JSONStorage to keep results, fixed trouble with IpGenerator
This commit is contained in:
parent
ee2de0decf
commit
acbfb6607b
14
storage/AbstractStorage.py
Normal file
14
storage/AbstractStorage.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractStorage(ABC):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@abstractmethod
|
||||||
|
def put_responce(self, address, responce):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@abstractmethod
|
||||||
|
def save(self):
|
||||||
|
pass
|
23
storage/JSONStorage.py
Normal file
23
storage/JSONStorage.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from AbstractStorage import AbstractStorage
|
||||||
|
import json
|
||||||
|
from threading import RLock
|
||||||
|
|
||||||
|
|
||||||
|
class JSONStorage(AbstractStorage):
|
||||||
|
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
self.respdict = dict()
|
||||||
|
self.lock = RLock()
|
||||||
|
|
||||||
|
def put_responce(self, address, responce):
|
||||||
|
ip, port = address
|
||||||
|
if ip not in self.respdict.keys():
|
||||||
|
self.respdict[ip] = {"open": [], "close": []}
|
||||||
|
self.respdict[ip]["open" if responce != 0 else "close"].append(port)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
print("saving")
|
||||||
|
with open(self.path, "w") as f:
|
||||||
|
json.dump(self.respdict, f)
|
||||||
|
self.respdict = {}
|
6
storage/__init__.py
Normal file
6
storage/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
fil = __file__[:__file__.rindex(os.sep)]
|
||||||
|
sys.path.insert(0,fil)
|
Loading…
Reference in New Issue
Block a user