-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirect_checker.py
More file actions
31 lines (24 loc) · 1014 Bytes
/
redirect_checker.py
File metadata and controls
31 lines (24 loc) · 1014 Bytes
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
import requests
def check_redirects(url):
try:
print(f"🔍 Checking redirects for: {url}\n")
response = requests.get(url, allow_redirects=True, timeout=10)
history = response.history
if not history:
print("✅ No redirects. Page resolves directly.\n")
return
print(f"🔁 Total Redirects: {len(history)}")
print("📜 Redirect Chain:")
for i, resp in enumerate(history):
print(f" {i+1}. {resp.status_code} → {resp.headers['Location']}")
# Detect potential loop
final_url = response.url
if final_url == url:
print("\n⚠️ Potential redirect loop detected: Final URL is same as the start URL.")
else:
print(f"\n✅ Final Destination: {final_url}")
except requests.exceptions.RequestException as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
url = input("🔗 Enter the URL (with https://): ").strip()
check_redirects(url)