Skip to content

Commit 7172537

Browse files
authored
add another python project for connectivity
1 parent d4cdf70 commit 7172537

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Utilities/connectivity.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#This code is made by MRayan Asim
2+
#Packages needed:
3+
#pip install requests
4+
import requests
5+
import time
6+
7+
def check_website_connectivity(url):
8+
try:
9+
start_time = time.time()
10+
response = requests.get(url)
11+
end_time = time.time()
12+
13+
if response.status_code == 200:
14+
speed = end_time - start_time
15+
print(f"The website {url} is reachable.")
16+
print(f"Response time: {speed:.2f} seconds")
17+
else:
18+
print(f"Error: The website {url} returned a status code {response.status_code}.")
19+
except requests.RequestException as e:
20+
print(f"Error: Unable to connect to the website {url}.")
21+
print(f"Exception: {e}")
22+
23+
if __name__ == "__main__":
24+
user_url = input("Enter the website URL: ")
25+
check_website_connectivity(user_url)

0 commit comments

Comments
 (0)