-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (42 loc) · 1.37 KB
/
main.py
File metadata and controls
55 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import re
from urllib.parse import urlparse
SUSPICIOUS_KEYWORDS = [
'login', 'free', 'bonus', 'click', 'update', 'verify', 'gift', 'win', 'cheap'
]
SHORTENING_SERVICES = [
'bit.ly', 'goo.gl', 'tinyurl.com', 't.co', 'ow.ly', 'buff.ly'
]
def is_ip_in_url(netloc):
return bool(re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', netloc))
def analyze_url(url):
parsed = urlparse(url)
netloc = parsed.netloc.lower()
path = parsed.path.lower()
score = 0
findings = []
if is_ip_in_url(netloc):
score += 2
findings.append("🔴 Uses IP address instead of domain")
if any(keyword in path for keyword in SUSPICIOUS_KEYWORDS):
score += 2
findings.append("🟠 Contains suspicious keywords")
if len(netloc.split('.')) > 3:
score += 1
findings.append("🟡 Has too many subdomains")
if any(service in netloc for service in SHORTENING_SERVICES):
score += 1
findings.append("🟡 Uses URL shortening service")
if len(url) > 75:
score += 1
findings.append("🟡 Unusually long URL")
risk = "Low"
if score >= 5:
risk = "High"
elif score >= 3:
risk = "Medium"
print(f"🛡️ Risk Level: {risk}")
for f in findings:
print(f"- {f}")
if __name__ == "__main__":
url = input("🔗 Enter a URL to analyze: ").strip()
analyze_url(url)