-
Notifications
You must be signed in to change notification settings - Fork 0
/
outcheckr.py
155 lines (119 loc) · 5.19 KB
/
outcheckr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import colorama
import sys
import argparse
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin
import os
import re
from concurrent.futures import ThreadPoolExecutor
colorama.init()
is_windows=sys.platform.startswith('win')
Green = colorama.Fore.GREEN
Magenta = colorama.Fore.MAGENTA
Red = colorama.Fore.RED
Reset = colorama.Fore.RESET
white = colorama.Fore.WHITE
if is_windows:
import win_unicode_console
win_unicode_console.enable()
prompt = '>>'
def banner():
banner = f"""{Green}
██████╗ ██╗ ██╗████████╗ ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗██████╗
██╔═══██╗██║ ██║╚══██╔══╝██╔════╝██║ ██║██╔════╝██╔════╝██║ ██╔╝██╔══██╗
██║ ██║██║ ██║ ██║ ██║ ███████║█████╗ ██║ █████╔╝ ██████╔╝
██║ ██║██║ ██║ ██║ ██║ ██╔══██║██╔══╝ ██║ ██╔═██╗ ██╔══██╗
╚██████╔╝╚██████╔╝ ██║ ╚██████╗██║ ██║███████╗╚██████╗██║ ██╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
{Reset}"""
print(banner)
print("Welcome to Outcheckr, an advanced tool for checking outbound links from a domain\n")
print("#Coded by Ashfaq Sadat\n\n")
parser = argparse.ArgumentParser("Argparser")
parser.add_argument('-u', '--url', help = "url to check for", required=True)
parser.add_argument('-n', '--no-color', help = "output without colors",required=False, action="store_true")
parser.add_argument('-v', '--verbose', help = "Display results real-time", required=False, action="store_true")
parser.add_argument('-o', '--output', help = "file to save the results", required=True)
parser.add_argument('-t', '--threads', help = "number of threads to use if you want to use threading", required=False, type=int, default=1)
args = parser.parse_args()
if args.no_color:
Green=""
Magenta = ""
Red = ""
Reset = ""
white = ""
banner()
if args.no_color:
print(f"{white}[-]{Green}no-color is on. colors are not displayed{Reset}\n")
if args.verbose:
print(f"{white}[-]{Green}verbosity is on. Output will be displayed{Reset}\n")
checkingurl = args.url
def get_outbound_links(domain):
try:
response = requests.get(domain)
response.raise_for_status()
except requests.RequestException as e:
print(f"Error fetching {domain}: {e}")
return []
soup = BeautifulSoup(response.text, 'html.parser')
tags = soup.find_all(href=True)
o_links = []
for link in tags :
url = link['href']
full_url = urljoin(domain, url)
domain_name = urlparse(domain).netloc
url_name = urlparse(full_url).netloc
if url_name and url_name != domain_name :
o_links.append(full_url)
if o_links :
return o_links
else:
return None
def sanitize(text):
sanitized = re.sub(r'[^a-zA-Z0-9_\-]', '_', text)
return sanitized
def parse_input_file(filen):
with open(f"./input/{filen}", "r") as file:
urls = [line.strip() for line in file]
return urls
def fetch_links_thread(url):
return get_outbound_links(url)
def file_write(filename, intype):
if ".txt" in filename:
pass
else:
filename = filename + ".txt"
if intype == "single":
ols = get_outbound_links(args.url)
file = open(f"./output/{filename}", "w")
for link in ols:
file.write(link+"\n")
elif intype == "multiple":
inputlinks = parse_input_file(filen=args.url)
outall = open(f"./output/{filename}", "w")
with ThreadPoolExecutor(max_workers=args.threads) as executor:
results = list(executor.map(fetch_links_thread, inputlinks))
for inlink, ll in zip(inputlinks, results):
os.makedirs(f"./output/(folder){filename}", exist_ok=True)
foldername = sanitize(inlink)
out = open(f"./output/(folder){filename}/{foldername}.txt", "w")
for link in ll:
out.write(link+"\n")
outall.write(link+"\n")
if args.output:
if ".txt" in args.url:
file_write(filename=args.output,intype="multiple")
else:
file_write(filename=args.output,intype="single")
print(f"{Green}Successfuly written to file!{Reset}")
if args.verbose:
fn = args.output
if ".txt" in fn :
pass
else:
fn = fn+".txt"
outfile = open(f"./output/{fn}", "r")
outs = outfile.readlines()
for link in outs:
print(link+"\n")