3
# Description: check is host:port is open, and supply the first line or 'banner'
4
# Author: Wijnand 'tehmaze' Modderman
7
""" show banner of <host> <port> """
9
__author__ = "Wijnand 'tehmaze' Modderman"
12
from gozerbot.commands import cmnds
13
from gozerbot.plughelp import plughelp
14
from gozerbot.examples import examples
15
from gozerbot.tests import tests
18
plughelp.add('banner', 'show if host:port is open')
20
def handle_banner(bot, ievent):
21
""" banner <host> <port> .. check if host:port is open """
23
(host, port) = ievent.args
26
ievent.missing('<host> <port>')
30
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32
sock.connect((host, port))
33
except socket.timeout:
34
ievent.reply('%s:%s is not up' % (host, port))
37
ievent.reply('%s:%s is not up ==> %s' % (host, port, str(ex)))
40
msock = sock.makefile()
41
banner = msock.readline()
49
ievent.reply('%s:%s is up: %s' % (host, port, banner))
51
ievent.reply('%s:%s is up' % (host, port))
53
cmnds.add('banner', handle_banner, 'USER')
54
examples.add('banner', 'banner <host> <port> // show if host:port is open', \
55
'banner gozerbot.org 25')
56
tests.add('banner gozerbot.org 25', 'up')