fabriziosalmi / websites-monitor

Websites monitoring via GitHub Actions (expiration, security, performances, privacy, SEO)
9 stars 7 forks source link

Check server software #5

Open fabriziosalmi opened 1 year ago

fabriziosalmi commented 1 year ago
import requests

def check_server_software(website):
    """
    Detect the web server software of the website.

    Args:
    - website (str): URL of the website to be checked.

    Returns:
    - str: "🟢" if server software is suppressed or not easily identifiable,
           "🔴" if server software is openly exposed,
           "⚪" for any errors.
    """

    try:
        response = requests.get(website)
        server_header = response.headers.get("Server")

        if server_header:
            print(f"Server software identified: {server_header}")
            return "🔴"
        else:
            return "🟢"

    except Exception as e:
        print(f"Error occurred: {e}")
        return "⚪"

print(check_server_software("https://example.com"))