import requests # Function to analyze HTTP headers def analyze_headers(url): try: response = requests.get(url) headers = response.headers print(f"HTTP Headers for {url}:\n") for header, value in headers.items(): print(f"{header}: {value}") # Check for common security headers security_headers = [ 'Content-Security-Policy', 'X-Content-Type-Options', 'X-Frame-Options', 'X-XSS-Protection', 'Strict-Transport-Security', 'Referrer-Policy', 'Feature-Policy', ] print("\nSecurity Header Analysis:") for header in security_headers: if header in headers: print(f"[+] {header} is present.") else: print(f"[-] {header} is missing.") except requests.exceptions.RequestException as e: print(f"Error fetching headers: {e}") if __name__ == "__main__": target_url = input("Enter the URL to analyze (e.g., http://example.com): ") analyze_headers(target_url)
Category: python
-
YAHHAS (Yet Another HTTP Header Analyzer Script)
-
DNS Enumeration Script
import dns.resolver import threading import time # Function to resolve a subdomain def resolve_subdomain(domain, subdomain, results): full_domain = f"{subdomain}.{domain}" try: answers = dns.resolver.resolve(full_domain, 'A') for answer in answers: results.append(full_domain) print(f"Found: {full_domain} -> {answer}") except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN): pass except Exception as e: print(f"Error resolving {full_domain}: {e}") # Function to perform DNS enumeration def dns_enum(domain, subdomains): results = [] threads = [] print(f"Starting DNS enumeration for {domain}...") for subdomain in subdomains: thread = threading.Thread(target=resolve_subdomain, args=(domain, subdomain, results)) threads.append(thread) thread.start() for thread in threads: thread.join() # Wait for all threads to complete return results if __name__ == "__main__": target_domain = input("Enter the target domain (e.g., example.com): ") subdomain_list = [ "www", "mail", "ftp", "test", "dev", "api", "blog", "shop", "admin", "secure", "staging", "portal", "test", "webmail", "status" ] # Add more subdomains as needed start_time = time.time() found_subdomains = dns_enum(target_domain, subdomain_list) end_time = time.time() print("\nEnumeration complete.") print(f"Total subdomains found: {len(found_subdomains)}") print(f"Time taken: {end_time - start_time:.2f} seconds")
-
YASPS (Yet Another Simple Port Scanner)
import socket import threading # Function to scan a single port def scan_port(ip, port, open_ports): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) # Set timeout for the connection result = sock.connect_ex((ip, port)) if result == 0: open_ports.append(port) sock.close() except Exception as e: print(f"Error scanning port {port}: {e}") # Function to perform the port scan def scan_ports(ip, start_port, end_port): open_ports = [] threads = [] print(f"Scanning {ip} for open ports from {start_port} to {end_port}...") for port in range(start_port, end_port + 1): thread = threading.Thread(target=scan_port, args=(ip, port, open_ports)) threads.append(thread) thread.start() for thread in threads: thread.join() # Wait for all threads to complete return open_ports if __name__ == "__main__": target_ip = input("Enter the IP address to scan: ") start_port = int(input("Enter the starting port number: ")) end_port = int(input("Enter the ending port number: ")) open_ports = scan_ports(target_ip, start_port, end_port) print("\nOpen ports:") if open_ports: for port in open_ports: print(f"Port {port} is open.") else: print("No open ports found.")
-
Simple Network Scanner Script
import os import platform import socket import sys def get_local_ip(): hostname = socket.gethostname() return socket.gethostbyname(hostname) def ping_command(ip): system_platform = platform.system().lower() if system_platform == "windows": return f"ping -n 1 -w 1000 {ip} > NUL" # Windows (suppress output) elif system_platform == "darwin": # macOS return f"ping -c 1 -W 1 {ip} > /dev/null" # Suppress output else: # Assume Linux/Unix return f"ping -c 1 -W 1 {ip} > /dev/null" # Suppress output def scan_network(local_ip): base_ip = '.'.join(local_ip.split('.')[:-1]) + '.' active_hosts = [] total_ips = 254 # Number of IPs to scan (1-254) print("Scanning the network...") for i in range(1, total_ips + 1): ip = base_ip + str(i) response = os.system(ping_command(ip)) if response == 0: active_hosts.append(ip) # Update progress bar progress = (i / total_ips) * 100 bar_length = 40 block = int(bar_length * progress // 100) progress_bar = "#" * block + "-" * (bar_length - block) sys.stdout.write(f"\r[{progress_bar}] {progress:.2f}% done") sys.stdout.flush() print() # Newline after progress bar return active_hosts if __name__ == "__main__": local_ip = get_local_ip() print(f"Your local IP address: {local_ip}") active_devices = scan_network(local_ip) print("\nActive devices in the network:") for device in active_devices: print(device)
-
Cute Animal Fact Generator Script
import random def get_random_animal_fact(): facts = [ "Did you know? Sea otters hold hands while sleeping to keep from drifting apart!", "A group of flamingos is called a 'flamboyance.'", "Cows have best friends and get stressed when they are separated.", "Honey never spoils. Archaeologists have found edible honey in ancient Egyptian tombs!", "Dolphins have names for each other and can call out for one another.", "Sloths can hold their breath longer than dolphins can!", "A baby elephant can stand up within 30 minutes of being born!", "Cats have five toes on their front paws, but only four on their back paws." ] return random.choice(facts) if __name__ == "__main__": print("Here's a cute animal fact for you:") print(get_random_animal_fact())
-
Persistent To-Do List Manager Script
import json import os def load_tasks(filename): if os.path.exists(filename): with open(filename, 'r') as file: return json.load(file) return [] def save_tasks(tasks, filename): with open(filename, 'w') as file: json.dump(tasks, file) def display_tasks(tasks): if not tasks: print("Your to-do list is empty.") else: print("Your To-Do List:") for index, task in enumerate(tasks, start=1): print(f"{index}. {task}") def main(): filename = 'tasks.json' tasks = load_tasks(filename) while True: print("\nOptions:") print("1. Add task") print("2. Remove task") print("3. View tasks") print("4. Exit") choice = input("Select an option (1-4): ") if choice == '1': task = input("Enter the task: ") tasks.append(task) save_tasks(tasks, filename) print(f"Task '{task}' added.") elif choice == '2': display_tasks(tasks) try: task_index = int(input("Enter the task number to remove: ")) - 1 if 0 <= task_index < len(tasks): removed_task = tasks.pop(task_index) save_tasks(tasks, filename) print(f"Task '{removed_task}' removed.") else: print("Invalid task number.") except ValueError: print("Please enter a valid number.") elif choice == '3': display_tasks(tasks) elif choice == '4': print("Exiting the To-Do List Manager.") break else: print("Invalid option. Please try again.") if __name__ == "__main__": main()
-
To-Do List Manager Script
def display_tasks(tasks): if not tasks: print("Your to-do list is empty.") else: print("Your To-Do List:") for index, task in enumerate(tasks, start=1): print(f"{index}. {task}") def main(): tasks = [] while True: print("\nOptions:") print("1. Add task") print("2. Remove task") print("3. View tasks") print("4. Exit") choice = input("Select an option (1-4): ") if choice == '1': task = input("Enter the task: ") tasks.append(task) print(f"Task '{task}' added.") elif choice == '2': display_tasks(tasks) try: task_index = int(input("Enter the task number to remove: ")) - 1 if 0 <= task_index < len(tasks): removed_task = tasks.pop(task_index) print(f"Task '{removed_task}' removed.") else: print("Invalid task number.") except ValueError: print("Please enter a valid number.") elif choice == '3': display_tasks(tasks) elif choice == '4': print("Exiting the To-Do List Manager.") break else: print("Invalid option. Please try again.") if __name__ == "__main__": main()
-
URL Shortener
import pyshorteners def shorten_url(long_url): s = pyshorteners.Shortener() short_url = s.tinyurl.short(long_url) return short_url if __name__ == "__main__": long_url = input("Enter the URL to shorten: ") short_url = shorten_url(long_url) print(f"Shortened URL: {short_url}")
-
News Headlines Fetcher
import requests def fetch_latest_news(api_key): url = f"https://newsapi.org/v2/top-headlines?country=us&apiKey={api_key}" response = requests.get(url) if response.status_code == 200: articles = response.json().get('articles') if articles: print("Latest News Headlines:") for article in articles: print(f"- {article['title']}") else: print("No articles found.") else: print(f"Error fetching news: {response.status_code}") if __name__ == "__main__": api_key = input("Enter your NewsAPI key: ") #sign up at newsapi to get an api key fetch_latest_news(api_key)
-
Website Change Monitor Script
import requests import time import hashlib def get_website_content(url): response = requests.get(url) return response.text def hash_content(content): return hashlib.sha256(content.encode('utf-8')).hexdigest() def monitor_website(url, check_interval): print(f"Monitoring changes to {url} every {check_interval} seconds...") initial_content = get_website_content(url) initial_hash = hash_content(initial_content) while True: time.sleep(check_interval) current_content = get_website_content(url) current_hash = hash_content(current_content) if current_hash != initial_hash: print(f"Change detected on {url}!") initial_hash = current_hash else: print("No changes detected.") if __name__ == "__main__": target_url = input("Enter a URL to monitor (e.g., http://example.com): ") interval = int(input("Enter the check interval in seconds: ")) monitor_website(target_url, interval)