def displayfunction_json(cur: Iterable[Record], dbase: DB, no_screenshots: bool = False) -> None: indent: Optional[int] if os.isatty(sys.stdout.fileno()): indent = 4 else: indent = None for h in cur: for fld in ["_id", "scanid"]: try: del h[fld] except KeyError: pass for port in h.get("ports", []): if no_screenshots: for fname in ["screenshot", "screendata"]: if fname in port: del port[fname] elif "screendata" in port: port["screendata"] = utils.encode_b64( dbase.from_binary(port["screendata"])) for script in port.get("scripts", []): if "masscan" in script and "raw" in script["masscan"]: script["masscan"]["raw"] = utils.encode_b64( dbase.from_binary(script["masscan"]["raw"])) json.dump(h, sys.stdout, indent=indent, default=dbase.serialize) sys.stdout.write("\n")
def display_distinct( dbase: DB, arg: str, flt: Filter, srt: Optional[Any], lmt: Optional[int], skp: Optional[int], ) -> None: for val in dbase.distinct(arg, flt=flt, sort=srt, limit=lmt, skip=skp): sys.stdout.write(str(val) + "\n")
def display_short(dbase: DB, flt: Filter, srt: Optional[Any], lmt: Optional[int], skp: Optional[int]) -> None: for val in dbase.distinct("addr", flt=flt, sort=srt, limit=lmt, skip=skp): sys.stdout.write(val + "\n")
def displayfunction_remove(flt: Filter, dbase: DB) -> None: dbase.remove_many(flt)
def displayfunction_explain(flt: Filter, dbase: DB) -> None: sys.stdout.write(dbase.explain(dbase._get(flt), indent=4) + "\n")