From 6b40133f6d03cecc0fdd131ee78f31542a0ac640 Mon Sep 17 00:00:00 2001 From: liuf5 Date: Tue, 23 Mar 2021 16:05:50 +0800 Subject: [PATCH 1/3] feat:add -v command --- setup.py | 6 ++++-- zoomeye/__init__.py | 1 + zoomeye/cli.py | 7 +++++++ zoomeye/data.py | 8 ++++++-- zoomeye/show.py | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 6d91bfa..14ca04c 100644 --- a/setup.py +++ b/setup.py @@ -11,13 +11,15 @@ """ from setuptools import setup +from zoomeye import __version__ + DEPENDENCIES = open('requirements.txt', 'r', encoding='utf-8').read().split('\n') README = open('README.rst', 'r', encoding='utf-8').read() setup( name='zoomeye', - version='2.0.4.2', + version=__version__, description='Python library and command-line tool for ZoomEye (https://www.zoomeye.org/doc)', long_description=README, long_description_content_type='text/x-rst', @@ -38,7 +40,7 @@ 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9' + 'Programming Language :: Python :: 3.9', 'Topic :: Software Development :: Libraries :: Python Modules', ], ) diff --git a/zoomeye/__init__.py b/zoomeye/__init__.py index 35a7c15..176a2b4 100644 --- a/zoomeye/__init__.py +++ b/zoomeye/__init__.py @@ -11,3 +11,4 @@ __name__ = 'zoomeye' __package__ = 'zoomeye' +__version__ = '2.0.4.2' diff --git a/zoomeye/cli.py b/zoomeye/cli.py index 60f1c72..dafbbe6 100644 --- a/zoomeye/cli.py +++ b/zoomeye/cli.py @@ -17,6 +17,11 @@ sys.path.insert(1, module_path) from zoomeye import core +from zoomeye import __version__ + + +def get_version(): + return __version__ class ZoomEyeParser(argparse.ArgumentParser): @@ -38,6 +43,8 @@ def main(): parser_info = subparsers.add_parser("info", help="Show ZoomEye account info") parser_info.set_defaults(func=core.info) + parser.add_argument('-v', '--version', action='version', version=get_version(), help='Display version') + # query zoomeye data parser_search = subparsers.add_parser( "search", diff --git a/zoomeye/data.py b/zoomeye/data.py index 2246626..1f6e1ae 100644 --- a/zoomeye/data.py +++ b/zoomeye/data.py @@ -146,11 +146,12 @@ def filter_search_data(keys, field_table, data): return result -def filter_history_data(fileds, host_data): +def filter_history_data(fileds, host_data, omit=True): """ filter historical data based on user input :param fileds: list, user input :param host_data: list, exclude web data + :param omit: bool, omit string flag return: all_data,list matched data return: port_count, set, count open ports non-repeating """ @@ -171,7 +172,10 @@ def filter_history_data(fileds, host_data): host_result = str(utc_time) # omit raw data, is too long if filed_item == 'raw': - host_result = show.omit_str(show.convert_str(host_result)) + if omit: + host_result = show.omit_str(show.convert_str(host_result)) + else: + host_result = show.convert_str(host_result) # replace None --> [unknown] if host_result is None: host_result = "[unknown]" diff --git a/zoomeye/show.py b/zoomeye/show.py index dd981cf..f0578aa 100644 --- a/zoomeye/show.py +++ b/zoomeye/show.py @@ -280,7 +280,7 @@ def print_filter_history(fileds, hist_data): """ filter_title = '' first_item = hist_data[0] - all_data, port_count = data.filter_history_data(fileds, hist_data) + all_data, port_count = data.filter_history_data(fileds, hist_data, omit=False) printf(first_item.get('ip')) dict_first_item = data.ZoomEyeDict(first_item) for dict_item in data.tables_history_info.keys(): From cc976ada9f35bb7e22981b13b5f6c1c05e06840f Mon Sep 17 00:00:00 2001 From: liuf5 Date: Tue, 23 Mar 2021 16:08:59 +0800 Subject: [PATCH 2/3] docs:update -v parameter help information --- zoomeye/cli.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/zoomeye/cli.py b/zoomeye/cli.py index dafbbe6..cd6382a 100644 --- a/zoomeye/cli.py +++ b/zoomeye/cli.py @@ -21,7 +21,7 @@ def get_version(): - return __version__ + return "ZoomEye-python version number {}".format(__version__) class ZoomEyeParser(argparse.ArgumentParser): @@ -42,8 +42,13 @@ def main(): # zoomeye account info parser_info = subparsers.add_parser("info", help="Show ZoomEye account info") parser_info.set_defaults(func=core.info) - - parser.add_argument('-v', '--version', action='version', version=get_version(), help='Display version') + # show version number + parser.add_argument( + '-v', '--version', + action='version', + version=get_version(), + help="Show program's version number and exit" + ) # query zoomeye data parser_search = subparsers.add_parser( From d6b9e73e38dba2a104635048464c3257b3385acd Mon Sep 17 00:00:00 2001 From: liuf5 Date: Tue, 23 Mar 2021 16:25:23 +0800 Subject: [PATCH 3/3] fix:remove more space --- zoomeye/plotlib.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/zoomeye/plotlib.py b/zoomeye/plotlib.py index 1d3494b..b1a06b0 100644 --- a/zoomeye/plotlib.py +++ b/zoomeye/plotlib.py @@ -37,7 +37,6 @@ def show_pie_chart(stat): :param stat: list, all data and label """ - print() if len(stat) > len(config.COLOR_TABLE): raise ("max support 10 items") @@ -64,7 +63,6 @@ def show_pie_chart(stat): else: print(ch) count += 1 - print() def unicode_output(): @@ -128,7 +126,6 @@ def generate_histogram(values, labels=None, force_ascii=False): :param force_ascii: bool, unicode or ascii output return :None """ - print() # max length and bar width matrix = get_matrix(values, 36, 1) @@ -163,8 +160,8 @@ def generate_histogram(values, labels=None, force_ascii=False): r = trim_zeros(row) data.append("".join(chars[item] for item in r)) out.append(fmt.format(*data)) - result = '\n'.join(out) + '\n' - print(result) + for item in out: + print(' ' + item)