Category: python

  • Basic Vulnerability Scanner Script

    import requests
    
    def check_sql_injection(url):
        payload = "' OR '1'='1"
        response = requests.get(url + payload)
        if "error" not in response.text.lower():
            return True
        return False
    
    def check_xss(url):
        payload = "<script>alert('XSS')</script>"
        response = requests.get(url + payload)
        if payload in response.text:
            return True
        return False
    
    def scan_vulnerabilities(url):
        print(f"Scanning {url} for vulnerabilities...")
        
        if check_sql_injection(url):
            print("Potential SQL Injection vulnerability found!")
        else:
            print("No SQL Injection vulnerability detected.")
    
        if check_xss(url):
            print("Potential XSS vulnerability found!")
        else:
            print("No XSS vulnerability detected.")
    
    if __name__ == "__main__":
        target_url = input("Enter a URL to scan for vulnerabilities (e.g., http://example.com): ")
        scan_vulnerabilities(target_url)
  • Random Compliment Generator

    import random
    
    def get_random_compliment():
        compliments = [
            "You're amazing!",
            "Your smile lights up the room.",
            "You have a great sense of humor!",
            "You're a true friend.",
            "You brighten my day!",
            "You're a wonderful person.",
            "You have a fantastic sense of style!",
            "You're incredibly talented."
        ]
        
        return random.choice(compliments)
    
    if __name__ == "__main__":
        print("Here's a compliment for you:")
        print(get_random_compliment())
  • WHOIS Lookup Script

    import whois
    
    def whois_lookup(domain):
        try:
            domain_info = whois.whois(domain)
            print(f"WHOIS information for {domain}:")
            print(f"  Domain Name: {domain_info.domain_name}")
            print(f"  Registrar: {domain_info.registrar}")
            print(f"  Creation Date: {domain_info.creation_date}")
            print(f"  Expiration Date: {domain_info.expiration_date}")
            print(f"  Name Servers: {domain_info.name_servers}")
        except Exception as e:
            print(f"Error retrieving WHOIS information for '{domain}': {e}")
    
    if __name__ == "__main__":
        target_domain = input("Enter a domain name to look up (e.g., example.com): ")
        whois_lookup(target_domain)
  • Security Headers Checker Script

    import requests
    
    def check_security_headers(url):
        try:
            response = requests.get(url)
            headers = response.headers
    
            security_headers = {
                "Strict-Transport-Security": headers.get("Strict-Transport-Security"),
                "X-Content-Type-Options": headers.get("X-Content-Type-Options"),
                "X-Frame-Options": headers.get("X-Frame-Options"),
                "X-XSS-Protection": headers.get("X-XSS-Protection"),
                "Content-Security-Policy": headers.get("Content-Security-Policy"),
            }
    
            print(f"Security headers for {url}:")
            for header, value in security_headers.items():
                if value:
                    print(f"  {header}: {value}")
                else:
                    print(f"  {header}: Not present")
    
        except requests.exceptions.RequestException as e:
            print(f"Error accessing '{url}': {e}")
    
    if __name__ == "__main__":
        target_url = input("Enter a URL to check security headers (e.g., http://example.com): ")
        check_security_headers(target_url)
  • Password Strength Checker

    import re
    
    def check_password_strength(password):
        length_criteria = len(password) >= 8
        digit_criteria = re.search(r'\d', password) is not None
        uppercase_criteria = re.search(r'[A-Z]', password) is not None
        lowercase_criteria = re.search(r'[a-z]', password) is not None
        special_char_criteria = re.search(r'[@$!%*?&]', password) is not None
    
        if all([length_criteria, digit_criteria, uppercase_criteria, lowercase_criteria, special_char_criteria]):
            return "Strong password!"
        elif length_criteria and (digit_criteria or uppercase_criteria or lowercase_criteria):
            return "Moderate password."
        else:
            return "Weak password."
    
    if __name__ == "__main__":
        password_input = input("Enter a password to check its strength: ")
        strength = check_password_strength(password_input)
        print(strength)
  • URL Status Checker Script

    import requests
    
    def check_url_status(url):
        try:
            response = requests.get(url)
            if response.status_code == 200:
                print(f"The URL '{url}' is up!")
            else:
                print(f"The URL '{url}' returned status code: {response.status_code}")
        except requests.exceptions.RequestException as e:
            print(f"Error accessing '{url}': {e}")
    
    if __name__ == "__main__":
        url_to_check = input("Enter a URL to check (e.g., http://example.com): ")
        check_url_status(url_to_check)
  • Simple DNS Lookup Script

    import socket
    
    def dns_lookup(domain):
        try:
            ip_address = socket.gethostbyname(domain)
            print(f"Domain: {domain}\nIP Address: {ip_address}")
        except socket.gaierror:
            print(f"Error: Unable to resolve domain '{domain}'")
    
    if __name__ == "__main__":
        domain_name = input("Enter a domain name (e.g., example.com): ")
        dns_lookup(domain_name)
  • Daily Motivational Quote Script

    import random
    
    def get_daily_quote():
        quotes = [
            "The only way to do great work is to love what you do. - Steve Jobs",
            "Success is not the key to happiness. Happiness is the key to success. - Albert Schweitzer",
            "Don't watch the clock; do what it does. Keep going. - Sam Levenson",
            "The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
            "Your limitation—it's only your imagination.",
            "Push yourself, because no one else is going to do it for you.",
            "Great things never come from comfort zones.",
            "Dream it. Wish it. Do it."
        ]
        
        return random.choice(quotes)
    
    if __name__ == "__main__":
        daily_quote = get_daily_quote()
        print("Today's Motivational Quote:")
        print(daily_quote)
  • Simple Python Port Scanner

    import socket
    
    def scan_ports(host, start_port, end_port):
        print(f"Scanning {host} from port {start_port} to {end_port}")
        for port in range(start_port, end_port + 1):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)  # Set a timeout for the connection
            result = sock.connect_ex((host, port))
            if result == 0:
                print(f"Port {port} is open")
            sock.close()
    
    if __name__ == "__main__":
        target_host = input("Enter the host to scan (e.g., 192.168.1.1): ")
        scan_ports(target_host, 1, 1024)  # Scanning ports 1 to 1024
  • Hello world!

    print("Hello world!")