-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
39 lines (34 loc) · 1.42 KB
/
utils.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
import requests
import urllib
def try_connection(url, follow_redirects=True):
try:
response = requests.get(url, timeout=10, allow_redirects=follow_redirects)
if response.status_code in (200, 3):
return {"success": True, "message":"Connection successful"}
else:
return {"success": False, "message": f"Connection failed. Status code: {response.status_code}"}
except requests.ConnectionError as e:
return {"success": False, "message":f"Connection failed: This may be due to a bad internet network or DNS resolution issue."}
except requests.Timeout as e:
return {"success": False, "message": f"Connection timed out."}
except requests.RequestException as e:
return {"success":False, "message": f"An error occurred during the request: {str(e)}"}
def print_banner() -> None:
print("""
______ _
| ___ \ | |
| |_/ /_ __ _ _| |_ ___ _ __
| ___ \ '__| | | | __/ _ \ '__|
| |_/ / | | |_| | || __/ |
\____/|_| \__,_|\__\___|_|
""")
if __name__ == "__main__":
print_banner()
url1 = "https://google.com/"
url2 = "http://example.com"
url3 = "http://qwdvqvqrevwerc.com"
url4 = "https://twitter.com/unexistingpageervwerwer"
print(try_connection(url1))
print(try_connection(url2))
print(try_connection(url3))
print(try_connection(url4))