Open fabriziosalmi opened 10 months ago
check_domain_breach.py
import requests
def check_domain_breach(website):
domain_breach = "π’" # Start with a default "safe" status.
try:
breach_url = f"https://breachdirectory.com/api/domain/{website}"
response = requests.get(breach_url)
if response.status_code != 200:
print(f"Error occurred while fetching breach data for {website}. Status Code: {response.status_code}")
domain_breach = "π" # Assume "grey" due to an API error.
else:
data = response.json()
# If the domain was found in any breaches, set the status to "red".
if data.get('found') and data['found'] == True:
domain_breach = "π΄"
except Exception as e:
print(f"An error occurred while checking breach data for {website}: {e}")
domain_breach = "βͺ" # Set "grey" due to a processing error.
return domain_breach
check_domain_expiraion.py
from datetime import datetime
import whois
def check_domain_expiration(domain):
"""
Check the expiration date of a domain.
Args:
- domain (str): The domain name to be checked.
Returns:
- str: "π’ (X days left)" if the domain has more than 30 days to expire,
"π‘ (X days left)" if the domain has between 15 to 30 days to expire,
"π΄ (X days left)" if the domain has less than 15 days to expire,
"βͺ" for other errors, where X is the number of days until expiration.
"""
def get_days_to_expire(exp_date):
"""Calculate the days remaining for expiration."""
if not exp_date:
return None
if isinstance(exp_date, list):
exp_date = exp_date[0]
return (exp_date - datetime.now()).days
try:
w = whois.whois(domain)
days_to_expire = get_days_to_expire(w.expiration_date)
if days_to_expire is None:
print(f"Couldn't retrieve expiration details for {domain}.")
return "π΄"
elif days_to_expire < 15:
return f"π΄ ({days_to_expire} days left)"
elif days_to_expire < 30:
return f"π‘ ({days_to_expire} days left)"
else:
return f"π’ ({days_to_expire} days left)"
except Exception as e:
print(f"An error occurred while checking domain expiration for {domain}: {e}")
return "βͺ"
check_ssl_cert.py
import ssl
import socket
from datetime import datetime
def check_ssl_cert(host, port=443):
"""
Check the SSL certificate of a given host for its validity period.
Args:
host (str): The hostname to check.
port (int, optional): The port number. Defaults to 443 (standard HTTPS port).
Returns:
str:
- "π’ (X days left)" if the certificate is valid and has more than 30 days left.
- "π‘ (X days left)" if the certificate is valid but has 30 days or fewer left.
- "π΄" if the certificate is expired or there's an SSL related error.
where X is the number of days left for the SSL certificate to expire.
"""
context = ssl.create_default_context()
try:
with socket.create_connection((host, port)) as conn:
with context.wrap_socket(conn, server_hostname=host) as sock:
cert = sock.getpeercert()
cert_expiry = datetime.strptime(cert['notAfter'], r"%b %d %H:%M:%S %Y %Z")
days_to_expire = (cert_expiry - datetime.utcnow()).days
if days_to_expire <= 0:
return "π΄"
elif days_to_expire <= 30:
return f"π‘ ({days_to_expire} days left)"
else:
return f"π’ ({days_to_expire} days left)"
except (ssl.SSLError, ssl.CertificateError):
return "π΄"
except Exception as e:
print(f"Unexpected error while checking SSL certificate for {host} on port {port}: {e}")
return "π΄"
check_dns_blacklist.py
import dns.resolver
def check_dns_blacklist(domain):
"""
Check if a domain is blacklisted in known DNS-based blacklists.
Args:
- domain (str): The domain name to be checked.
Returns:
- str: "π’" if the domain is not in any blacklist,
"π΄" if the domain is found in a blacklist.
"""
# Set of DNS blacklists
blacklists = {
"zen.spamhaus.org",
"bl.spamcop.net"
# ... You can add more blacklists here
}
for blacklist in blacklists:
try:
dns.resolver.query(f"{domain}.{blacklist}", 'A')
return "π΄"
except dns.resolver.NXDOMAIN:
continue # The domain is not blacklisted in this blacklist
except (dns.resolver.NoAnswer, dns.resolver.Timeout, dns.resolver.NoNameservers):
continue # Ignore these errors for the sake of the check
return "π’"
check_domainsblacklists_blacklist.py
import requests
def check_domainsblacklists_blacklist(domain):
url = "https://get.domainsblacklists.com/blacklist.txt"
try:
response = requests.get(url, stream=True, timeout=10)
response.raise_for_status()
# We'll use an iterative approach to prevent loading the entire list into memory.
# This will search the file line by line.
for line in response.iter_lines(decode_unicode=True):
if line.strip() == domain:
return "π΄"
return "π’"
except requests.RequestException:
return "βͺ" # Return gray if there's an error in fetching or processing.
main.py