Code Monkey home page Code Monkey logo

Comments (5)

fabriziosalmi avatar fabriziosalmi commented on May 21, 2024

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

from websites-monitor.

fabriziosalmi avatar fabriziosalmi commented on May 21, 2024

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 "⚪"

from websites-monitor.

fabriziosalmi avatar fabriziosalmi commented on May 21, 2024

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 "🔴"

from websites-monitor.

fabriziosalmi avatar fabriziosalmi commented on May 21, 2024

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 "🟢"

from websites-monitor.

fabriziosalmi avatar fabriziosalmi commented on May 21, 2024

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.

from websites-monitor.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.