def __init__(self, ip, port): self.ip = ip self.port = port self.host = None self.id = None self.scope = True self.scanned = False self.reachable = None self.found = None self.auth = [] c = dbConn.get().cursor() c.execute( 'SELECT id,host,scanned,reachable,auth,scope,found FROM endpoints WHERE ip=? AND port=?', (self.ip, self.port)) savedEndpoint = c.fetchone() c.close() if savedEndpoint is not None: self.id = savedEndpoint[0] self.host = Host.find(savedEndpoint[1]) self.scanned = savedEndpoint[2] != 0 if savedEndpoint[3] is None: self.reachable = None else: self.reachable = savedEndpoint[3] != 0 if savedEndpoint[4] is not None: self.auth = json.loads(savedEndpoint[4]) self.scope = savedEndpoint[5] != 0 if savedEndpoint[6] is not None: self.found = Endpoint.find(savedEndpoint[6])
def findAll(cls): ret = [] c = dbConn.get().cursor() for row in c.execute('SELECT src,dst FROM paths'): ret.append(Path(Host.find(row[0]), Endpoint.find(row[1]))) c.close() return ret
def findByDst(cls, dst): ret = [] c = dbConn.get().cursor() for row in c.execute('SELECT src,dst FROM paths WHERE dst=?', (dst.getId(), )): ret.append(Path(Host.find(row[0]), Endpoint.find(row[1]))) c.close() return ret
def find(cls, pathId): c = dbConn.get().cursor() c.execute('''SELECT src,dst FROM paths WHERE id=?''', (pathId, )) row = c.fetchone() c.close() if row == None: return None return Path(Host.find(row[0]), Endpoint.find(row[1]))