@@ -528,12 +528,9 @@ def timeout_check(value):
528528
529529
530530def handler (signal_received ,frame ):
531- """Exit gracefully without throwing errors
532-
533- Source: https://www.devdungeon.com/content/python-catch-sigint-ctrl-c
534- """
535- sys .exit (0 )
536-
531+ """Handle SIGINT (Ctrl-C) gracefully and stop threads immediately."""
532+ print ("\n Action cancelled by user." ,file = sys .stderr )
533+ os ._exit (1 )# hard exit avoids threading shutdown noise
537534
538535def main ():
539536parser = ArgumentParser (
@@ -820,57 +817,90 @@ def main():
820817all_usernames .append (name )
821818else :
822819all_usernames .append (username )
823- for username in all_usernames :
824- results = sherlock (
825- username ,
826- site_data ,
827- query_notify ,
828- dump_response = args .dump_response ,
829- proxy = args .proxy ,
830- timeout = args .timeout ,
831- )
832820
833- if args .output :
834- result_file = args .output
835- elif args .folderoutput :
836- # The usernames results should be stored in a targeted folder.
837- # If the folder doesn't exist, create it first
838- os .makedirs (args .folderoutput ,exist_ok = True )
839- result_file = os .path .join (args .folderoutput ,f"{ username } .txt" )
840- else :
841- result_file = f"{ username } .txt"
842-
843- if args .output_txt :
844- with open (result_file ,"w" ,encoding = "utf-8" )as file :
845- exists_counter = 0
846- for website_name in results :
847- dictionary = results [website_name ]
848- if dictionary .get ("status" ).status == QueryStatus .CLAIMED :
849- exists_counter += 1
850- file .write (dictionary ["url_user" ]+ "\n " )
851- file .write (f"Total Websites Username Detected On :{ exists_counter } \n " )
852-
853- if args .csv :
854- result_file = f"{ username } .csv"
855- if args .folderoutput :
821+ try :
822+ for username in all_usernames :
823+ results = sherlock (
824+ username ,
825+ site_data ,
826+ query_notify ,
827+ dump_response = args .dump_response ,
828+ proxy = args .proxy ,
829+ timeout = args .timeout ,
830+ )
831+
832+ if args .output :
833+ result_file = args .output
834+ elif args .folderoutput :
856835# The usernames results should be stored in a targeted folder.
857836# If the folder doesn't exist, create it first
858837os .makedirs (args .folderoutput ,exist_ok = True )
859- result_file = os .path .join (args .folderoutput ,result_file )
860-
861- with open (result_file ,"w" ,newline = "" ,encoding = "utf-8" )as csv_report :
862- writer = csv .writer (csv_report )
863- writer .writerow (
864- [
865- "username" ,
866- "name" ,
867- "url_main" ,
868- "url_user" ,
869- "exists" ,
870- "http_status" ,
871- "response_time_s" ,
872- ]
873- )
838+ result_file = os .path .join (args .folderoutput ,f"{ username } .txt" )
839+ else :
840+ result_file = f"{ username } .txt"
841+
842+ if args .output_txt :
843+ with open (result_file ,"w" ,encoding = "utf-8" )as file :
844+ exists_counter = 0
845+ for website_name in results :
846+ dictionary = results [website_name ]
847+ if dictionary .get ("status" ).status == QueryStatus .CLAIMED :
848+ exists_counter += 1
849+ file .write (dictionary ["url_user" ]+ "\n " )
850+ file .write (f"Total Websites Username Detected On :{ exists_counter } \n " )
851+
852+ if args .csv :
853+ result_file = f"{ username } .csv"
854+ if args .folderoutput :
855+ # The usernames results should be stored in a targeted folder.
856+ os .makedirs (args .folderoutput ,exist_ok = True )
857+ result_file = os .path .join (args .folderoutput ,result_file )
858+
859+ with open (result_file ,"w" ,newline = "" ,encoding = "utf-8" )as csv_report :
860+ writer = csv .writer (csv_report )
861+ writer .writerow (
862+ [
863+ "username" ,
864+ "name" ,
865+ "url_main" ,
866+ "url_user" ,
867+ "exists" ,
868+ "http_status" ,
869+ "response_time_s" ,
870+ ]
871+ )
872+ for site in results :
873+ if (
874+ args .print_found
875+ and not args .print_all
876+ and results [site ]["status" ].status != QueryStatus .CLAIMED
877+ ):
878+ continue
879+
880+ response_time_s = results [site ]["status" ].query_time
881+ if response_time_s is None :
882+ response_time_s = ""
883+ writer .writerow (
884+ [
885+ username ,
886+ site ,
887+ results [site ]["url_main" ],
888+ results [site ]["url_user" ],
889+ str (results [site ]["status" ].status ),
890+ results [site ]["http_status" ],
891+ response_time_s ,
892+ ]
893+ )
894+
895+ if args .xlsx :
896+ usernames = []
897+ names = []
898+ url_main = []
899+ url_user = []
900+ exists = []
901+ http_status = []
902+ response_time_s = []
903+
874904for site in results :
875905if (
876906args .print_found
@@ -879,62 +909,39 @@ def main():
879909 ):
880910continue
881911
882- response_time_s = results [site ]["status" ].query_time
883912if response_time_s is None :
884- response_time_s = ""
885- writer .writerow (
886- [
887- username ,
888- site ,
889- results [site ]["url_main" ],
890- results [site ]["url_user" ],
891- str (results [site ]["status" ].status ),
892- results [site ]["http_status" ],
893- response_time_s ,
894- ]
895- )
896- if args .xlsx :
897- usernames = []
898- names = []
899- url_main = []
900- url_user = []
901- exists = []
902- http_status = []
903- response_time_s = []
904-
905- for site in results :
906- if (
907- args .print_found
908- and not args .print_all
909- and results [site ]["status" ].status != QueryStatus .CLAIMED
910- ):
911- continue
912-
913- if response_time_s is None :
914- response_time_s .append ("" )
915- else :
916- response_time_s .append (results [site ]["status" ].query_time )
917- usernames .append (username )
918- names .append (site )
919- url_main .append (results [site ]["url_main" ])
920- url_user .append (results [site ]["url_user" ])
921- exists .append (str (results [site ]["status" ].status ))
922- http_status .append (results [site ]["http_status" ])
923-
924- DataFrame = pd .DataFrame (
925- {
926- "username" :usernames ,
927- "name" :names ,
928- "url_main" : [f'=HYPERLINK(\" { u } \" )' for u in url_main ],
929- "url_user" : [f'=HYPERLINK(\" { u } \" )' for u in url_user ],
930- "exists" :exists ,
931- "http_status" :http_status ,
932- "response_time_s" :response_time_s ,
933- }
934- )
935- DataFrame .to_excel (f"{ username } .xlsx" ,sheet_name = "sheet1" ,index = False )
913+ response_time_s .append ("" )
914+ else :
915+ response_time_s .append (results [site ]["status" ].query_time )
916+ usernames .append (username )
917+ names .append (site )
918+ url_main .append (results [site ]["url_main" ])
919+ url_user .append (results [site ]["url_user" ])
920+ exists .append (str (results [site ]["status" ].status ))
921+ http_status .append (results [site ]["http_status" ])
922+
923+ DataFrame = pd .DataFrame (
924+ {
925+ "username" :usernames ,
926+ "name" :names ,
927+ "url_main" : [f'=HYPERLINK(\" { u } \" )' for u in url_main ],
928+ "url_user" : [f'=HYPERLINK(\" { u } \" )' for u in url_user ],
929+ "exists" :exists ,
930+ "http_status" :http_status ,
931+ "response_time_s" :response_time_s ,
932+ }
933+ )
934+ DataFrame .to_excel (f"{ username } .xlsx" ,sheet_name = "sheet1" ,index = False )
935+
936+ print ()
937+ except KeyboardInterrupt :
938+ print ("\n Action cancelled by user." ,file = sys .stderr )
939+ try :
940+ query_notify .finish ()
941+ except Exception :
942+ pass
943+ sys .exit (1 )
936944
937- print ()
938945query_notify .finish ()
939946
940947