Skip to content

Commit fdb6825

Browse files
authored
Merge pull request larymak#112 from amitp970/main
Added Server Checker
2 parents 7c4749d + aea8778 commit fdb6825

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ServerChecker/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Description
2+
The script can be used to check if a certain server is up or not.
3+
4+
## Steps for Execution
5+
1. Fork this repository
6+
2. Find the serverCheck.py file and run it.
7+
3. Enter the website's name you would like to check.
8+
4. If you would like to go again answer with 'Y', otherwise write 'N'

ServerChecker/serverChecker.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import socket
2+
3+
def is_running(site):
4+
"""This function attempts to connect to the given server using a socket.
5+
Returns: Whether or not it was able to connect to the server."""
6+
try:
7+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
sock.connect((site, 80))
9+
return True
10+
except:
11+
return False
12+
13+
if __name__ == "__main__":
14+
while True:
15+
site = input('Website to check: ')
16+
if is_running(f'{site}.com'):
17+
print(f"{site}.com is running!")
18+
else:
19+
print(f'There is a problem with {site}.com!')
20+
21+
if input("Would You like to check another website(Y/N)? ") in {'n', 'N'}:
22+
break
23+

0 commit comments

Comments
 (0)