Check File

This script will help you efficiently check for the existence of file across multiple URLs while skipping any that are unreachable.

2024-11-14 17:45:38 - Coderja

import requests

# Read the list of URLs from a file
with open('myweb.txt', 'r') as file:
    urls = file.readlines()

# Check each URL for the existence of uploadwp.php with a timeout
for url in urls:
    url = url.strip()  # Remove whitespace
    if not url:
        continue  # Skip empty lines

    # Construct the full URL to check
    check_url = f"{url}/uploadwp.php"

    try:
        response = requests.head(check_url, timeout=5)  # Set timeout to 5 seconds
        if response.status_code == 200:
            print(f"{check_url} - File exists.")
        else:
            print(f"{check_url} - File does not exist (status code: {response.status_code}).")
    except requests.exceptions.Timeout:
        print(f"{check_url} - Request timed out, skipping.")
    except requests.exceptions.RequestException as e:
        print(f"{check_url} - Unable to access URL: {e}")

More Posts