Monday, October 22, 2018

Logging to a Cisco WLC via a Jumpserver from a Windows 7 host without Cygwin

Is there any Python module (or anything similar in any other language you could recommend) available which would allow to establish an ssh connection from pure Windows environment (specifically Windows 7)?

I can get what I need using Cygwin and pexpect, however my manager wants me to convert my scripts in such a way as to make .exe files out of them that my co-workers who don't want to install Cygwin and Python on their machines could use them as well.

Before I can form executables out of them, and even before I connect to the Cisco WLC directly, I first need to establish an ssh connection (on port 8022) with the Jumpserver itself and even that proves to be tricky on pure Windows. For instance, here's the error code I get with the following script:

from Exscript.util.interact import read_login from Exscript.protocols import SSH2 account = read_login() conn = SSH2() conn.connect('XXX.YY.ZZZ.AAA', 8022) conn.login(account) conn.execute('show version') print(conn.response) conn.send('exit\r') conn.close() 

The error msg:

C:\Users\ABC\Desktop\XYZ Projekt>py XYZ_init.pyPlease enter your user name [ABC]: ABCPlease enter your password:Traceback (most recent call last):   File "XYZ_init.py", line 7, in <module>     conn.login(account)   File "C:\Python36\lib\site-packages\Exscript\protocols\protocol.py", line 674,  in login     self.authenticate(account, flush=False)   File "C:\Python36\lib\site-packages\Exscript\protocols\protocol.py", line 698,  in authenticate     self.protocol_authenticate(account)   File "C:\Python36\lib\site-packages\Exscript\protocols\protocol.py", line 725,  in protocol_authenticate     self._protocol_authenticate(user, password)   File "C:\Python36\lib\site-packages\Exscript\protocols\ssh2.py", line 339, in _protocol_authenticate     self._paramiko_shell()   File "C:\Python36\lib\site-packages\Exscript\protocols\ssh2.py", line 320, in _paramiko_shell     rows, cols = get_terminal_size()   File "C:\Python36\lib\site-packages\Exscript\util\tty.py", line 119, in get_te rminal_size     close_fds=True)   File "C:\Python36\lib\subprocess.py", line 624, in __init__     "close_fds is not supported on Windows platforms" ValueError: close_fds is not supported on Windows platforms if you redirect stdi n/stdout/stderr

PS. I already asked a similar question in r/learnpython section but they weren't able to help me much so perhaps I'll have better luck here, with people who actually deal with networks on a daily basis. :)



No comments:

Post a Comment