2021-09-18 11:32:31 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-09-15 19:37:41 +00:00
|
|
|
import argparse
|
2021-09-18 11:32:31 +00:00
|
|
|
import os
|
2021-09-15 19:37:41 +00:00
|
|
|
import sys
|
2021-09-16 05:33:11 +00:00
|
|
|
import json
|
2021-09-15 19:37:41 +00:00
|
|
|
|
2021-09-18 11:32:31 +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
|
|
|
)
|
2024-11-23 15:59:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--unique",
|
|
|
|
action="store_true",
|
|
|
|
help="Return the best CPE matching the keywords given",
|
|
|
|
default=False,
|
|
|
|
)
|
2021-09-18 11:32:31 +00:00
|
|
|
args = parser.parse_args()
|
2021-09-16 05:33:11 +00:00
|
|
|
|
2021-09-18 11:32:31 +00:00
|
|
|
cpeGuesser = CPEGuesser()
|
2024-11-23 15:59:36 +00:00
|
|
|
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))
|