Port can be defined as host:port

This commit is contained in:
Termonoid 2021-01-31 10:27:22 +03:00
parent 87771c7505
commit a54a938c2f
2 changed files with 17 additions and 16 deletions

View File

@ -103,15 +103,13 @@ class CheckerTargetPortHandler(CheckerBaseHandler):
def process_args_for_host_port(text: str, default_port: int) -> list:
port = None
args = text.split()
if len(args) < 2:
port = default_port
args = text.split(' ', 1)
if len(args) != 2:
raise NotEnoughArgs()
if len(args) == 2:
port = default_port
if len(args) == 3:
port = args[2]
if not check_int(port):
raise InvalidPort()
host = args[1]
if ":" in host:
host, port = host.rsplit(":", 1)
elif " " in host:
host, port = host.rsplit(" ", 1)
return [host, port]

View File

@ -29,15 +29,18 @@ class TCPCheckerHandler(CheckerTargetPortHandler):
await super(TCPCheckerHandler, self).handler(message)
async def process_args(self, text: str) -> list:
port = None
args = text.split()
if len(args) < 3:
args = text.split(' ', 1)
if len(args) != 2:
raise NotEnoughArgs()
if len(args) >= 3:
port = args[2]
if not check_int(port):
raise InvalidPort()
host = args[1]
if ":" in host:
host, port = host.rsplit(":", 1)
elif " " in host:
host, port = host.split(maxsplit=1)
else:
raise NotEnoughArgs()
if not check_int(port):
raise InvalidPort()
return [host, port]
async def prepare_message(self, res: Response):