commit abe5d5073e849992eac3ec4795b8f0be05ddeac1 Author: Michaël Paulon Date: Sat Aug 8 14:53:43 2020 +0200 init 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()