Skip to content

Commit 3f3a03b

Browse files
committed
Adding verbosity logging
1 parent f24d901 commit 3f3a03b

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ class Plugin(AbstractPlugin):
134134
- [X] Plugin: SSL
135135
- [X] Minium severity argument
136136
- [X] Plugin: HTTP
137+
- [X] Wire up verbosity
137138
- [ ] Plugin: Shares
138139
- [ ] Plugin: Interesting Ports
139-
- [ ] Wire up verbosity

logger.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
from enum import Enum
3+
4+
5+
class LogLevel(Enum):
6+
INFO = 0
7+
DEBUG = 1
8+
VERBOSE =2
9+
SPAM = 3
10+
11+
12+
class Log(object):
13+
14+
def __init__(self, level):
15+
self.level = level
16+
17+
def write(self, val, level=LogLevel.INFO, end=None, flush=None):
18+
if self.level >= level.value:
19+
print(val, end=end, flush=flush)

showdown.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter
88
from getpass import getpass
99
from download import Downloader
10+
from logger import Log, LogLevel
1011
from shared import Pipeline, Severity
1112
from plugin import PluginRegistry
1213
from shodanapi import ShodanAPI
@@ -80,42 +81,45 @@ def ip_processed(has_details):
8081

8182

8283
def main(args):
84+
log = Log(args.verbose)
8385
formatter_reg = FormattersRegistry(args)
8486
plugin_reg = PluginRegistry()
8587
pipeline = Pipeline()
8688
plugins = plugin_reg.retrieve_plugins(args.plugins)
8789

88-
print(__BANNER__)
89-
print('[*] Starting up')
90-
90+
if not args.no_banner:
91+
print(__BANNER__)
92+
93+
log.write('[*] Starting up')
94+
9195
api_key = get_api_key(args)
9296
ips = args.retrieve_ips(args)
9397
api = ShodanAPI(api_key)
94-
print('[*] Testing shodan')
98+
log.write('[*] Testing shodan', LogLevel.DEBUG)
9599
success, result = api.test()
96100
if success:
97-
cprint("[*] Successful Shodan call.", 'green')
98-
cprint(f"[*] {result}", 'blue')
101+
log.write(colored("[*] Successful Shodan call.", 'green'), LogLevel.DEBUG)
102+
log.write(colored(f"[*] {result}", 'blue'), LogLevel.VERBOSE)
99103
else:
100104
raise SystemExit(colored(f"[!] Error calling Shodan: '{result}'.", 'red'))
101105

102-
print(f"[+] IPs: {' '.join(ips)}")
103-
print(f"[+] Plugins: {' '.join(args.plugins)}")
106+
log.write(f"[+] IPs: {' '.join(ips)}")
107+
log.write(f"[+] Plugins: {' '.join(args.plugins)}")
104108

105109
for plugin in plugins:
106110
pipeline.register(plugin)
107111

108-
cprint('[+] Details', 'green', end=' ')
109-
cprint('[-] No details', 'red')
110-
print(f"[+] Processing {len(ips)} hosts: ", end='', flush=True)
112+
log.write(colored('[+] Details', 'green'), end=' ')
113+
log.write(colored('[-] No details', 'red'))
114+
log.write(f"[+] Processing {len(ips)} hosts: ", end='', flush=True)
111115

112116
downloader = Downloader(api, args.threads, ips)
113117
hosts = downloader.download(processed_callback=ip_processed)
114118
print()
115119

116120
# no details for any of the hosts, nothing more to do!
117121
if not hosts:
118-
cprint('[!] No hosts with details', 'red')
122+
log.write(colored('[!] No hosts with details', 'red'))
119123
return
120124

121125
# process the hosts through the plugins
@@ -128,7 +132,7 @@ def main(args):
128132
for ip, host in output.items():
129133
formatter.format(ip, host)
130134

131-
cprint('[*] Done.', 'green')
135+
log.write(colored('[*] Done.', 'green'))
132136

133137

134138
if __name__ == '__main__':
@@ -146,6 +150,7 @@ def main(args):
146150
parser.add_argument('--output', '-o', help='Output file to use (default: stdout).', type=FileType('w'), default='-', metavar='FILE')
147151
parser.add_argument('--no-color',help='Outputs to console with no color (default: %(default)s).', action='store_true', default=False)
148152
parser.add_argument('--min-severity', type=Severity.from_name, help='Minimum severity to report on (default: INFO).', metavar='SEVERITY', choices=Severity.all(), default=Severity.INFO)
153+
parser.add_argument('--no-banner', '-nb', action='store_true', default=False, help='Prevents the banner from being displayed.')
149154

150155
# input from file
151156
file_parser = subparsers.add_parser('file')

0 commit comments

Comments
 (0)