Mercurial > prosody-modules
diff mod_portcheck/mod_portcheck.lua @ 4897:42a362a2bf51
mod_portcheck: Shell command to check if ports are open
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 18 Feb 2022 18:35:45 +0100 |
parents | |
children | adecfb36349e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_portcheck/mod_portcheck.lua Fri Feb 18 18:35:45 2022 +0100 @@ -0,0 +1,18 @@ +module:set_global(); +local portmanager = require "core.portmanager"; + +local commands = module:shared("admin_shell/commands") + +function commands.portcheck(session, line) + for desc, interface, port in line:gmatch("%s(%[?([%x:.]+)%]?:(%d+))") do + if interface == "*" then + interface = "0.0.0.0"; + end + assert(portmanager.get_service_at(interface, tonumber(port)), desc); + end + session.print "OK"; +end + +function module.unload() + commands.portcheck = nil; +end