| import re |
| import math |
| import whois |
| import datetime |
|
|
| |
| |
| |
| def analyze_url(url): |
| score = 0 |
| reasons = [] |
|
|
| if not url.startswith("https"): |
| score += 1 |
| reasons.append("URL is not HTTPS secure") |
|
|
| if re.search(r"\d+\.\d+\.\d+\.\d+", url): |
| score += 1 |
| reasons.append("IP address detected in URL") |
|
|
| suspicious_words = ["login", "verify", "bank", "secure", "update"] |
| for word in suspicious_words: |
| if word in url.lower(): |
| score += 1 |
| reasons.append(f"Suspicious word detected: {word}") |
|
|
| |
| try: |
| domain_info = whois.whois(url) |
| creation_date = domain_info.creation_date |
| if isinstance(creation_date, list): |
| creation_date = creation_date[0] |
| if creation_date: |
| age_days = (datetime.datetime.now() - creation_date).days |
| if age_days < 180: |
| score += 1 |
| reasons.append("Newly registered domain (<6 months)") |
| except: |
| pass |
|
|
| if score == 0: |
| return "✅ Safe URL" |
| elif score == 1: |
| return "⚠️ Slightly Suspicious\n" + "\n".join(reasons) |
| else: |
| return "🚨 High Risk URL\n" + "\n".join(reasons) |
|
|
| |
| |
| |
| def password_strength(password): |
| length = len(password) |
| entropy = length * math.log2(94) |
|
|
| strength = "Weak" |
| if length >= 8 and re.search(r"[A-Z]", password) and re.search(r"[0-9]", password): |
| strength = "Medium" |
| if length >= 12 and re.search(r"[!@#$%^&*]", password): |
| strength = "Strong" |
|
|
| crack_time = round(2 ** (entropy / 10)) |
| return f"Strength: {strength}\nEntropy: {round(entropy,2)}\nEstimated Crack Attempts: {crack_time}" |