diff options
| author | 2019-10-08 15:46:15 +0100 | |
|---|---|---|
| committer | 2019-10-08 15:46:15 +0100 | |
| commit | 15782908db3c506b98d00f37158b970543b28ca2 (patch) | |
| tree | 10fd4bae3d2bdd25c7dd9fc27c5cf6a3706b2fcf /modules | |
| parent | show $n/$u/$h for ban-format-account help too (diff) | |
| signature | ||
add !isupraw - to check if a tcp connection is possible to a target
closes #120
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/isup.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/isup.py b/modules/isup.py index 3251718a..55f00479 100644 --- a/modules/isup.py +++ b/modules/isup.py @@ -1,3 +1,4 @@ +import socket from src import ModuleManager, utils class Module(ModuleManager.BaseModule): @@ -18,3 +19,29 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("%s looks up to me (HTTP %d)" % (url, response.code)) + + @utils.hook("received.command.isupraw") + @utils.kwarg("min_args", 1) + @utils.kwarg("help", "Check if a given hostname:port is up or not") + @utils.kwarg("usage", "<hostname>[:port]") + def isupraw(self, event): + hostname, _, port = event["args_split"][0].partition(":") + port = utils.parse.try_int(port or "80") + if port == None: + raise utils.EventError("Port must be a number") + + error = None + try: + with utils.deadline(seconds=5): + socket.create_connection((hostname, port)) + except utils.DeadlineExceededException: + error = "timed out" + except Exception as e: + error = str(e) + + if error == None: + event["stdout"].write("%s:%d looks up to me" % (hostname, port)) + else: + event["stderr"].write("%s:%d looks down to me (%s)" % + (hostname, port, error)) + |
