Last active
May 18, 2023 16:35
-
-
Save AyrtonB/eea651a50bd978e543a8a7b018417e15 to your computer and use it in GitHub Desktop.
Python function for checking whether a site is down or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
def isitdown(domain, return_bool=True): | |
""" | |
Uses the website 'isitdownrightnow.com' to check | |
whether the domain provided is down or not. | |
Parameters | |
---------- | |
domain : str | |
The url for the website that is to be checked | |
return_bool : bool | |
True means 'down'/'up' is returned whilst | |
False means True/False is returned | |
Returns | |
------- | |
bool/str | |
True/'down' if site is down, False/'up' otherwise. | |
""" | |
isitdown_url = f'https://www.isitdownrightnow.com/check.php?domain={domain}' | |
r = requests.get(isitdown_url) | |
r_text = (r | |
.text | |
.lower() | |
.replace('</div>', ' ') | |
) | |
status = (re | |
.compile(f'{domain} is (.*) (?:it is not|and reachable)') | |
.search(r_text) | |
.group(1) | |
.split(' ') | |
[0] | |
) | |
if return_bool == True: | |
return status == 'down' | |
else: | |
return status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment