Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6932bd0

Browse files
committed
Fix: clean exit when SIGINIT
1 parent842ae1f commit6932bd0

File tree

1 file changed

+114
-107
lines changed

1 file changed

+114
-107
lines changed

‎sherlock_project/sherlock.py‎

Lines changed: 114 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,9 @@ def timeout_check(value):
528528

529529

530530
defhandler(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("\nAction cancelled by user.",file=sys.stderr)
533+
os._exit(1)# hard exit avoids threading shutdown noise
537534

538535
defmain():
539536
parser=ArgumentParser(
@@ -820,57 +817,90 @@ def main():
820817
all_usernames.append(name)
821818
else:
822819
all_usernames.append(username)
823-
forusernameinall_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-
ifargs.output:
834-
result_file=args.output
835-
elifargs.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-
ifargs.output_txt:
844-
withopen(result_file,"w",encoding="utf-8")asfile:
845-
exists_counter=0
846-
forwebsite_nameinresults:
847-
dictionary=results[website_name]
848-
ifdictionary.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-
ifargs.csv:
854-
result_file=f"{username}.csv"
855-
ifargs.folderoutput:
821+
try:
822+
forusernameinall_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+
ifargs.output:
833+
result_file=args.output
834+
elifargs.folderoutput:
856835
# The usernames results should be stored in a targeted folder.
857836
# If the folder doesn't exist, create it first
858837
os.makedirs(args.folderoutput,exist_ok=True)
859-
result_file=os.path.join(args.folderoutput,result_file)
860-
861-
withopen(result_file,"w",newline="",encoding="utf-8")ascsv_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+
ifargs.output_txt:
843+
withopen(result_file,"w",encoding="utf-8")asfile:
844+
exists_counter=0
845+
forwebsite_nameinresults:
846+
dictionary=results[website_name]
847+
ifdictionary.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+
ifargs.csv:
853+
result_file=f"{username}.csv"
854+
ifargs.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+
withopen(result_file,"w",newline="",encoding="utf-8")ascsv_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+
forsiteinresults:
873+
if (
874+
args.print_found
875+
andnotargs.print_all
876+
andresults[site]["status"].status!=QueryStatus.CLAIMED
877+
):
878+
continue
879+
880+
response_time_s=results[site]["status"].query_time
881+
ifresponse_time_sisNone:
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+
ifargs.xlsx:
896+
usernames= []
897+
names= []
898+
url_main= []
899+
url_user= []
900+
exists= []
901+
http_status= []
902+
response_time_s= []
903+
874904
forsiteinresults:
875905
if (
876906
args.print_found
@@ -879,62 +909,39 @@ def main():
879909
):
880910
continue
881911

882-
response_time_s=results[site]["status"].query_time
883912
ifresponse_time_sisNone:
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-
ifargs.xlsx:
897-
usernames= []
898-
names= []
899-
url_main= []
900-
url_user= []
901-
exists= []
902-
http_status= []
903-
response_time_s= []
904-
905-
forsiteinresults:
906-
if (
907-
args.print_found
908-
andnotargs.print_all
909-
andresults[site]["status"].status!=QueryStatus.CLAIMED
910-
):
911-
continue
912-
913-
ifresponse_time_sisNone:
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}\")'foruinurl_main],
929-
"url_user": [f'=HYPERLINK(\"{u}\")'foruinurl_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}\")'foruinurl_main],
928+
"url_user": [f'=HYPERLINK(\"{u}\")'foruinurl_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+
exceptKeyboardInterrupt:
938+
print("\nAction cancelled by user.",file=sys.stderr)
939+
try:
940+
query_notify.finish()
941+
exceptException:
942+
pass
943+
sys.exit(1)
936944

937-
print()
938945
query_notify.finish()
939946

940947

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp