-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode with Explanation.py
41 lines (32 loc) · 1.38 KB
/
Code with Explanation.py
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
#Module import
import requests
#To get a colorful output
from colorama import Fore, Back, Style
#Creating a function
def track_url(url):
#Try and Except rule
try:
#Passing input url in the requests module
resp = requests.get(url)
#CHWCKING FOR REDIRECTED SITES
#If exists the history of the redirected sites are printed
if resp.history:
print(Fore.RED + '\nYes URL is Redirected or Shorten!')
print(Fore.RED + 'Here the following redirected chain...\n')
for r in resp.history:
print(Fore.RED + '|', r.status_code, '|', r.url, '|', r.reason)
print(Fore.GREEN + '\nEND URL :', resp.url)
print(Fore.GREEN + 'Status Code :', resp.status_code, resp.reason)
else:
print(Fore.WHITE + '\nURL is Not Redirected or Shorten!')
print(Fore.WHITE + 'END URL :', resp.url)
print(Fore.WHITE + 'Status Code :',resp.status_code, resp.reason)
# To check the url is valid or not
except BaseException as be:
print(Fore.RED + 'Tracking Failed! Check URL')
print(be)
exit()
#To get the url from user
link = input("Enter the link : ")
#To call the function
track_url(link)