-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckForRedirection.py
More file actions
32 lines (26 loc) · 846 Bytes
/
CheckForRedirection.py
File metadata and controls
32 lines (26 loc) · 846 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
#!/usr/bin/python
import sys
import requests
def check_for_redirects(url):
try:
r = requests.get(url,allow_redirects=False,timeout=0.5)
if 300 <= r.status_code < 400:
return r.headers['location']
else:
return '[no redirect]'
except requests.exceptions.Timeout:
return '[TimeOut]'
except requests.exceptions.ConnectionError:
return '[ConnectionTimeOut]'
def Check_domains(urls):
for url in urls:
check_url = url if url.startswith('http') else "http://%s" % url
redirect_url = check_for_redirects(check_url)
print("%s==>%s" % (check_url,redirect_url))
if __name__ == '__main__':
try:
fname = sys.argv[1]
except IndexError:
pass
urls = ( url.strip() for url in open(fname).readlines() )
Check_domains(urls)