chg: [lookup] use positional arguments for WORD(s)

This commit is contained in:
Esa Jokinen 2021-09-22 17:16:23 +03:00
parent 93fbc1a0da
commit 4678307483
2 changed files with 16 additions and 19 deletions

View file

@ -50,53 +50,55 @@ curl -s -X POST https://cpe-guesser.cve-search.org/search -d "{\"query\": [\"out
### Command line - `lookup.py` ### Command line - `lookup.py`
~~~~ ~~~~
usage: lookup.py [-h] [--word WORD] usage: lookup.py [-h] WORD [WORD ...]
Find potential CPE names from a list of keyword(s) and return a JSON of the results Find potential CPE names from a list of keyword(s) and return a JSON of the results
positional arguments:
WORD One or more keyword(s) to lookup
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--word WORD One or more keyword(s) to lookup
~~~~ ~~~~
~~~~ ~~~~
python3 lookup.py --word microsoft --word sql --word server | jq . python3 lookup.py microsoft sql server | jq .
[ [
[ [
51076, 51325,
"cpe:2.3:a:microsoft:sql_server_2017_reporting_services" "cpe:2.3:a:microsoft:sql_server_2017_reporting_services"
], ],
[ [
51077, 51326,
"cpe:2.3:a:microsoft:sql_server_2019_reporting_services" "cpe:2.3:a:microsoft:sql_server_2019_reporting_services"
], ],
[ [
57612, 57898,
"cpe:2.3:a:quest:intrust_knowledge_pack_for_microsoft_sql_server" "cpe:2.3:a:quest:intrust_knowledge_pack_for_microsoft_sql_server"
], ],
[ [
60090, 60386,
"cpe:2.3:o:microsoft:sql_server" "cpe:2.3:o:microsoft:sql_server"
], ],
[ [
60660, 60961,
"cpe:2.3:a:microsoft:sql_server_desktop_engine" "cpe:2.3:a:microsoft:sql_server_desktop_engine"
], ],
[ [
64489, 64810,
"cpe:2.3:a:microsoft:sql_server_reporting_services" "cpe:2.3:a:microsoft:sql_server_reporting_services"
], ],
[ [
75465, 75858,
"cpe:2.3:a:microsoft:sql_server_management_studio" "cpe:2.3:a:microsoft:sql_server_management_studio"
], ],
[ [
77161, 77570,
"cpe:2.3:a:microsoft:sql_server" "cpe:2.3:a:microsoft:sql_server"
], ],
[ [
77793, 78206,
"cpe:2.3:a:ibm:tivoli_storage_manager_for_databases_data_protection_for_microsoft_sql_server" "cpe:2.3:a:ibm:tivoli_storage_manager_for_databases_data_protection_for_microsoft_sql_server"
] ]
] ]

View file

@ -12,13 +12,8 @@ from lib.cpeguesser import CPEGuesser
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Find potential CPE names from a list of keyword(s) and return a JSON of the results') parser = argparse.ArgumentParser(description='Find potential CPE names from a list of keyword(s) and return a JSON of the results')
parser.add_argument('--word', help='One or more keyword(s) to lookup', action='append') parser.add_argument('word', metavar='WORD', type=str, nargs='+', help='One or more keyword(s) to lookup')
args = parser.parse_args() args = parser.parse_args()
if args.word is None:
print("Missing keyword(s)")
parser.print_help()
sys.exit(1)
cpeGuesser = CPEGuesser() cpeGuesser = CPEGuesser()
print(json.dumps(cpeGuesser.guessCpe(args.word))) print(json.dumps(cpeGuesser.guessCpe(args.word)))