Categories We Write About

Create a website uptime checker

Here’s a simple website uptime checker script in Python that you can use to monitor whether a website is up or down. It uses the requests library to ping the site and reports the status based on the HTTP response code.

python
import requests def check_website_uptime(url, timeout=5): try: response = requests.get(url, timeout=timeout) if response.status_code == 200: return f"Website {url} is UP." else: return f"Website {url} returned status code {response.status_code}." except requests.exceptions.RequestException as e: return f"Website {url} is DOWN. Error: {e}" if __name__ == "__main__": url = input("Enter the website URL to check (include http/https): ") status = check_website_uptime(url) print(status)

How this works:

  • The script tries to perform a GET request to the given URL.

  • If the response code is 200, it means the website is reachable and considered up.

  • If the status code is anything else, it reports that code.

  • If an exception occurs (timeout, DNS error, no connection), it reports the website as down.

If you want me to write a more advanced uptime checker with features like scheduled checks, email alerts, or a web interface, just ask!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About