21 lines
588 B
Python
21 lines
588 B
Python
import socket, time
|
|
|
|
def checkPort(domain,port,rest=5):
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
sock.settimeout(1)
|
|
ret = (sock.connect_ex((domain,port))==0)
|
|
sock.close()
|
|
time.sleep(rest)
|
|
return ret
|
|
|
|
def checkTilde(domain):
|
|
# Check port 22 availability (SSH)
|
|
ssh = checkPort(domain,22)
|
|
# Check port 80 and/or 443 availability (Web)
|
|
web = checkPort(domain,80) or checkPort(domain,443)
|
|
# Check port 70 (gopher default port)
|
|
gopher = checkPort(domain,70)
|
|
# Assemble life report
|
|
ret = dict(ssh=ssh,web=web,gopher=gopher,alive=(ssh or web or gopher))
|
|
return ret
|