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.")
Author: admin
-
YASPS (Yet Another Simple Port Scanner)
-
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) -
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())