-
At the root level of the project, add the executable file
main.py
,Here, take the testing of nmap_python as an example. Add the executable file
main.py
under./lev-hub/szczecin.nmap_python/
:
from lev.szczecin.nmap_python import nmap
# levrt.run can only execute asynchronous functions, so when testing, the target method needs to be encapsulated by an asynchronous function first.
async def test_alive(ip: str):
result = await nmap.alive(ip)
data = await result.get()
print(data)
if __name__ == "__main__":
import levrt
# log related code
# logger related commands can enable the compiler command line to output debugging data when the tool is executed
import logging
logging.basicConfig()
logger = logging.getLogger("lev")
logger.setLevel(logging.DEBUG)
levrt.run(test_alive("192.168.1.1/24"))
Execute the command in the current directory:
$ pdm run python main.py
If you want to debug during the local testing, you can use levrt.run() to execute your modes and workflows locally, then use pdb for breakpoint debugging locally.
You need to import pdb under the remote method. If you import it externally, you will be prompted that the module cannot be found.
def raw(argv:list[str]) -> Cr:
@remote
def entry(argv):
import pdb
待完善
If you want to view the files inside the container, use the command docker cp
instead of directly using docker start
to start the container.
Restarting the container will cause the task to be re-executed, which will affect the last output.
There are many reasons why you may encounter failures during the testing process. Here are some common ones:
-
Connect call failed ('127.0.0.1', 38379)
Because of the defects of docker itself, the containers cannot access each other after the computer sleeps, and the docker service needs to be restarted. It may also cause the following devices to go offline.
-
Device offline
The agent cannot connect to the server. You need to execute the
ssh lev agent | sudo docker run -v /var/run/docker.sock:/docker --rm -i talentsec/lev
command to re-pull and execute the agent.