Add script to check server status. #646
This commit is contained in:
parent
e986d07f70
commit
f81e33521f
1 changed files with 30 additions and 0 deletions
30
utils/server_status/check_server_status.py
Normal file
30
utils/server_status/check_server_status.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import sys
|
||||
import socket
|
||||
|
||||
# TODO: make port a constant? 80 for http
|
||||
# 443 for https
|
||||
def servertest(argv):
|
||||
host = argv[1]
|
||||
port = int(argv[2])
|
||||
|
||||
print (host)
|
||||
print (port)
|
||||
|
||||
args = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)
|
||||
for family, socktype, proto, canonname, sockaddr in args:
|
||||
s = socket.socket(family, socktype, proto)
|
||||
|
||||
print (sockaddr)
|
||||
try:
|
||||
s.connect_ex(sockaddr)
|
||||
except socket.error:
|
||||
return False
|
||||
else:
|
||||
s.close()
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
if servertest(sys.argv):
|
||||
print("Server is up")
|
||||
else:
|
||||
print("Server is down")
|
||||
Loading…
Reference in a new issue