5
""" check if host:port is open """
7
__copyright__ = 'this file is in the public domain'
9
from gozerbot.commands import cmnds
10
from gozerbot.plughelp import plughelp
11
from gozerbot.examples import examples
12
from gozerbot.tests import tests
16
plughelp.add('probe', 'show if host:port is open')
18
def handle_probe(bot, ievent):
19
""" probe <host> <port> .. check if host:port is open """
21
(host, port) = ievent.args
24
ievent.missing('<host> <port>')
27
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
29
sock.connect((host, port))
31
except socket.timeout:
32
ievent.reply('%s:%s is not up' % (host, port))
35
ievent.reply('%s:%s is not up ==> %s' % (host, port, str(ex)))
37
ievent.reply('%s:%s is up' % (host, port))
39
cmnds.add('probe', handle_probe, ['OPER', 'PROBE'])
40
examples.add('probe', 'probe <host> <port> // show if host:port is open', \
41
'probe gozerbot.org 8088')
42
tests.add('probe gozerbot.org 10101')