Skip to content

Instantly share code, notes, and snippets.

@AyrtonB
Last active May 18, 2023 16:35
Show Gist options
  • Save AyrtonB/eea651a50bd978e543a8a7b018417e15 to your computer and use it in GitHub Desktop.
Save AyrtonB/eea651a50bd978e543a8a7b018417e15 to your computer and use it in GitHub Desktop.
Python function for checking whether a site is down or not
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