cpe-guesser/bin/lookup.py

42 lines
1,006 B
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2021-09-15 19:37:41 +00:00
import argparse
import os
2021-09-15 19:37:41 +00:00
import sys
import json
2021-09-15 19:37:41 +00:00
runPath = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(runPath, ".."))
from lib.cpeguesser import CPEGuesser
2021-09-15 19:37:41 +00:00
2024-04-05 14:03:23 +00:00
if __name__ == "__main__":
2021-10-19 16:30:29 +00:00
parser = argparse.ArgumentParser(
2024-04-05 14:03:23 +00:00
description="Find potential CPE names from a list of keyword(s) and return a JSON of the results"
2021-10-19 16:30:29 +00:00
)
parser.add_argument(
2024-04-05 14:03:23 +00:00
"word",
metavar="WORD",
2021-10-19 16:30:29 +00:00
type=str,
2024-04-05 14:03:23 +00:00
nargs="+",
help="One or more keyword(s) to lookup",
2021-10-19 16:30:29 +00:00
)
parser.add_argument(
"--unique",
action="store_true",
help="Return the best CPE matching the keywords given",
default=False,
)
args = parser.parse_args()
cpeGuesser = CPEGuesser()
r = cpeGuesser.guessCpe(args.word)
if not args.unique:
print(json.dumps(r))
else:
try:
r = r[:1][0][1]
except:
r = []
print(json.dumps(r))