|
1 | 1 | import requests |
2 | 2 | import sys |
3 | | -from colorama import Fore, Style, init |
4 | | -import urllib3 |
5 | | -from requests.exceptions import Timeout, RequestException |
| 3 | +from colorama import init, Fore, Style |
6 | 4 |
|
7 | | -# Initialize colorama for colorized output |
| 5 | +# Initialize colorama |
8 | 6 | init(autoreset=True) |
9 | 7 |
|
10 | | -# Suppress SSL warnings |
11 | | -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
| 8 | +def check_subdomains(subdomain_file): |
| 9 | + with open(subdomain_file, 'r') as f: |
| 10 | + subdomains = f.read().splitlines() |
12 | 11 |
|
13 | | -# Function to check the status code of each subdomain |
14 | | -def check_subdomains(file_path): |
15 | | - try: |
16 | | - with open(file_path, 'r') as file: |
17 | | - subdomains = file.readlines() |
18 | | - |
19 | | - for subdomain in subdomains: |
20 | | - subdomain = subdomain.strip() # Removing newline characters |
21 | | - if subdomain: # If the line is not empty |
22 | | - try: |
23 | | - response = requests.get(f"http://{subdomain}", timeout=10, verify=False) |
24 | | - status_code = response.status_code |
| 12 | + headers = { |
| 13 | + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' |
| 14 | + } |
25 | 15 |
|
26 | | - if status_code == 200: |
27 | | - print(f"{Fore.GREEN}[{status_code}] - {subdomain}") |
28 | | - elif status_code == 403: |
29 | | - print(f"{Fore.RED}[{status_code}] - {subdomain}") |
30 | | - elif status_code == 404: |
31 | | - print(f"{Fore.WHITE}[{status_code}] - {subdomain}") |
32 | | - else: |
33 | | - print(f"{Fore.WHITE}[{status_code}] - {subdomain}") |
34 | | - |
35 | | - except Timeout: |
36 | | - print(f"{Fore.WHITE}[TIMEOUT] - {subdomain}") |
37 | | - except RequestException as e: |
38 | | - print(f"{Fore.WHITE}[CONNECTION ERROR] - {subdomain}") |
39 | | - |
40 | | - except FileNotFoundError: |
41 | | - print(f"File '{file_path}' not found.") |
| 16 | + for subdomain in subdomains: |
| 17 | + try: |
| 18 | + response = requests.get(f"https://{subdomain}", timeout=10, headers=headers, verify=False) |
| 19 | + if response.status_code == 200: |
| 20 | + print(Fore.GREEN + "[200] - " + subdomain) |
| 21 | + elif response.status_code == 403: |
| 22 | + print(Fore.RED + "[403] - " + subdomain) |
| 23 | + elif response.status_code == 404: |
| 24 | + print(Fore.WHITE + "[404] - " + subdomain) |
| 25 | + else: |
| 26 | + print(Fore.WHITE + f"[{response.status_code}] - {subdomain}") |
| 27 | + except requests.exceptions.Timeout: |
| 28 | + print(Fore.WHITE + "[TIMEOUT] - " + subdomain) |
| 29 | + except requests.exceptions.ConnectionError: |
| 30 | + print(Fore.WHITE + "[CONNECTION ERROR] - " + subdomain) |
| 31 | + except Exception as e: |
| 32 | + print(Fore.WHITE + f"[ERROR] - {subdomain}: {str(e)}") |
42 | 33 |
|
43 | 34 | if __name__ == "__main__": |
44 | | - if len(sys.argv) != 3: |
45 | | - print("Usage: python check_http.py -l <subdomains.txt>") |
46 | | - elif sys.argv[1] == "-l": |
47 | | - check_subdomains(sys.argv[2]) |
| 35 | + if len(sys.argv) != 3 or sys.argv[1] != '-l': |
| 36 | + print("Usage: python3 check_http.py -l <subdomains_file>") |
| 37 | + sys.exit(1) |
| 38 | + check_subdomains(sys.argv[2]) |
0 commit comments