77from argparse import ArgumentParser , FileType , RawDescriptionHelpFormatter
88from getpass import getpass
99from download import Downloader
10+ from logger import Log , LogLevel
1011from shared import Pipeline , Severity
1112from plugin import PluginRegistry
1213from shodanapi import ShodanAPI
@@ -80,42 +81,45 @@ def ip_processed(has_details):
8081
8182
8283def 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
134138if __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