单线程:
import requests
url=input("请输入URL:").strip()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
}
print("Ciallo~ (∠・ω< )⌒★")
def read_file(file1):
"""尝试以 UTF-8 读取文件,失败后尝试 GBK"""
try:
with open(file1, encoding='utf-8') as f:
return f.readlines()
except UnicodeDecodeError:
with open(file1, encoding='gbk', errors='ignore') as f:
return f.readlines()
def run():
urls=read_file("main.txt")#字典
results = []
for sub in urls:
sub=sub.strip()
full_url=f"http://{sub}.{url}"
try:
response = requests.get(full_url, headers=headers, timeout=5) # 添加超时
if response.status_code == 200:
red_text = f"\033[91m[+] {full_url} 存在\033[0m" # 红色高亮
print(red_text)
results.append(f"[+] {full_url} 存在")
else:
print(f"[-] {full_url} 不存在")
except requests.exceptions.RequestException as e:
print(f"[!] 访问 {full_url} 失败: {e}")
return "\n".join(results)
# 执行扫描并保存结果
with open("output.txt", 'w', encoding='utf-8') as f:
result = run()
if result:
f.write(result)
多线程:
import requests
import concurrent.futures
import queue
# 获取 URL
url = input("请输入 URL:").strip()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
}
print("Ciallo~ (∠・ω< )⌒★")
def read_file(file_path):
"""尝试以 UTF-8 读取文件,失败后尝试 GBK"""
try:
with open(file_path, encoding='utf-8') as f:
return [line.strip() for line in f.readlines()]
except UnicodeDecodeError:
with open(file_path, encoding='gbk', errors='ignore') as f:
return [line.strip() for line in f.readlines()]
def scan_path(subdomain):
"""扫描单个子域名"""
full_url = f"http://{subdomain}.{url}"
try:
response = requests.get(full_url, headers=headers, timeout=5)
if response.status_code == 200:
result = f"\033[91m[+] {full_url} 存在\033[0m"
print(result)
return result
else:
print(f"[-] {full_url} 不存在")
except requests.exceptions.RequestException as e:
print(f"[!] 访问 {full_url} 失败: {e}")
return None
def run():
"""使用多线程执行扫描"""
subdomains = read_file("main.txt") # 读取子域名字典
results = []
q = queue.Queue()
for sub in subdomains:
q.put(sub) # 加入队列
max_threads = 10 # 线程池大小
with concurrent.futures.ThreadPoolExecutor(max_workers=max_threads) as executor:
futures = []
while not q.empty():
sub = q.get()
futures.append(executor.submit(scan_path, sub))
for future in concurrent.futures.as_completed(futures):
result = future.result()
if result:
results.append(result)
return "\n".join(results)
# 执行扫描并保存结果
if __name__ == "__main__":
result = run()
if result:
with open("output.txt", 'w', encoding='utf-8') as f:
f.write(result)
print("扫描完成,结果已保存到 output.txt")