import gradio as gr import re from urllib.parse import urlparse def check_link_safety(url): if not url.strip(): return "❌ Please enter a URL", [] risks = [] url_lower = url.lower() # Check for HTTPS if not url.startswith('https://'): risks.append("⚠️ Not using secure HTTPS") # Check for IP addresses if re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', url): risks.append("⚠️ Contains IP address instead of domain") # Check for URL shorteners if any(short in url_lower for short in ['bit.ly', 'tinyurl', 'short']): risks.append("⚠️ Uses URL shortener") # Check for suspicious keywords if re.search(r'(?:free|win|prize|claim|urgent|verify|account|suspended)', url_lower): risks.append("⚠️ Contains suspicious keywords") if len(risks) == 0: return "✅ URL appears safe", [] else: return "⚠️ Potential security risks detected", "\n".join(risks) def check_password_strength(password): if not password: return "Please enter a password", "", [] score = 0 checks = [] if len(password) >= 12: score += 1 checks.append("✅ At least 12 characters") else: checks.append("❌ At least 12 characters") if re.search(r'[A-Z]', password): score += 1 checks.append("✅ Contains uppercase letters") else: checks.append("❌ Contains uppercase letters") if re.search(r'[a-z]', password): score += 1 checks.append("✅ Contains lowercase letters") else: checks.append("❌ Contains lowercase letters") if re.search(r'\d', password): score += 1 checks.append("✅ Contains numbers") else: checks.append("❌ Contains numbers") if re.search(r'[!@#$%^&*(),.?":{}|<>]', password): score += 1 checks.append("✅ Contains special characters") else: checks.append("❌ Contains special characters") if score <= 2: strength = "🔴 Weak Password" elif score <= 3: strength = "🟡 Medium Password" else: strength = "🟢 Strong Password" return strength, f"Score: {score}/5", "\n".join(checks) def validate_email(email): if not email.strip(): return "Please enter an email address", "" email_regex = r'^[^\s@]+@[^\s@]+\.[^\s@]+$' if not re.match(email_regex, email): return "❌ Invalid email format", "" domain = email.split('@')[1].lower() suspicious = ['tempmail', 'throwaway', 'guerrilla', '10minute'] info = f"Domain: {domain}\n" if any(sus in domain for sus in suspicious): return "⚠️ Possible disposable email detected", info return "✅ Email format is valid", info # Create Gradio interface with gr.Blocks(theme=gr.themes.Soft()) as app: gr.Markdown("# 🛡️ Cyber Security Toolkit") gr.Markdown("Check links, test passwords, and validate emails") with gr.Tab("Link Safety Checker"): with gr.Row(): link_input = gr.Textbox(label="Enter URL", placeholder="https://example.com") link_button = gr.Button("Check Link Safety", variant="primary") link_output = gr.Textbox(label="Result") link_risks = gr.Textbox(label="Security Risks", lines=5) link_button.click(check_link_safety, inputs=link_input, outputs=[link_output, link_risks]) with gr.Tab("Password Strength"): with gr.Row(): pwd_input = gr.Textbox(label="Enter Password", type="password") pwd_button = gr.Button("Check Password Strength", variant="primary") pwd_strength = gr.Textbox(label="Strength") pwd_score = gr.Textbox(label="Score") pwd_checks = gr.Textbox(label="Requirements", lines=6) pwd_button.click(check_password_strength, inputs=pwd_input, outputs=[pwd_strength, pwd_score, pwd_checks]) with gr.Tab("Email Validator"): with gr.Row(): email_input = gr.Textbox(label="Enter Email", placeholder="user@example.com") email_button = gr.Button("Validate Email", variant="primary") email_output = gr.Textbox(label="Result") email_info = gr.Textbox(label="Email Info", lines=3) email_button.click(validate_email, inputs=email_input, outputs=[email_output, email_info]) app.launch()