Commit 79ac25dd authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Add closed port notifier

parent 44fb3f9f
#!/usr/bin/python3
import time, setuptools, porttools, twitools
hosts = setuptools.getListSetting("Ports", "hosts")
retry = int(setuptools.getSetting("Ports", "retry"))
two = twitools.twObject()
for h in hosts:
if not porttools.isPortOpen(h[0], h[1]):
time.sleep(retry)
if not porttools.isPortOpen(h[0], h[1]):
two.tweet("@%s Port %s is not open on host %s!" % (h[2], h[1], h[0]))
import socket
def isPortOpen(host, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
sock.connect((host, port))
except:
return False
return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment