From abe5d5073e849992eac3ec4795b8f0be05ddeac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Paulon?= Date: Sat, 8 Aug 2020 14:53:43 +0200 Subject: [PATCH] init --- requirements.txt | 1 + test.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 requirements.txt create mode 100644 test.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f4105ce --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +ssh2-python==0.18.0.post1 diff --git a/test.py b/test.py new file mode 100644 index 0000000..9cae0ea --- /dev/null +++ b/test.py @@ -0,0 +1,36 @@ +import socket + +from ssh2.session import Session +from ssh2.utils import wait_socket + +class Test() + +def get_output(channel): + out = b"" + size, data = channel.read(255) + while True: + out += data + if size < 255: + break + size, data = channel.read(255) + return out.decode() + + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect(("192.168.1.3", 22)) +s.setblocking(False) +session = Session() +session.handshake(s) +session.userauth_password("crans", "test1234") +chan = session.open_session() +chan.shell() +get_output(chan) +get_output(chan) +chan.write("\n") +get_output(chan) # random shit +chan.write("show run\n") +get_output(chan) # du garbage après l'exécution d'une commande +running_config = get_output(chan) +print(running_config) + +chan.close()