From 21b4e9b23400d43f0310b10cfab744c6ca3edf65 Mon Sep 17 00:00:00 2001 From: Roi Date: Thu, 25 Mar 2021 16:05:21 +0200 Subject: [PATCH] Fixed index out of range error There could be a situation where `findall` doesn't find anything, in this case I add a check to avoid errors. --- webwrap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webwrap.py b/webwrap.py index e8cb185..910f119 100644 --- a/webwrap.py +++ b/webwrap.py @@ -15,8 +15,11 @@ reg = """\]LEDEBUT\]([\s\S]*)\]LAFIN\]""" req = httpx.get(host.replace("WRAP", "echo -n ]LEDEBUT]$(whoami)[$(hostname)[$(pwd)]LAFIN]")) - prefixes = re.compile(reg).findall(req.text)[0].split("[") - path = prefixes[2] + prefixes = re.compile(reg).findall(req.text) + if not prefixes: + print("Req.text not found!\n") + exit(-1) + path = prefixes[0].split("[")[2] prefix = colored(prefixes[0] + "@" + prefixes[1], "red") + ":" + colored(prefixes[2], "cyan") + "$ " print("")