Juniper Script how to call Pyez using different ssh port

493 views
Skip to first unread message

Taz

unread,
Jun 25, 2020, 7:08:37 AM6/25/20
to Junos Python EZ

I have a requirement to logon to juniper devices using a port other than ssh 22 - This mean to ssh but using port say 8022 instead. 

How do I edit this code or has any one got some examples:

 

from pprint import pprint
from jnpr.junos import Device
from jnpr.junos.utils.start_shell import StartShell
hostname= Device(host='10.1.1.1', user='root', password='test123
' ** port required is 8022 instead of 22**
ss = StartShell(hostname)
ss.open()
hostname.open()
pprint(ss.run('cli -c "show version | no-more"'))       # <-- For regular CLI commands
pprint(ss.run('cprod -A fpc0 -c "show route summary"')) # <-- For VTY commands
hostname.close()
ss.close()

Save the above contents as ".py" file and run it using the following command:

python3 filename.py

Nitin Kumar

unread,
Jun 25, 2020, 7:11:40 AM6/25/20
to Taz, Junos Python EZ

Device(host='10.1.1.1', user='root', password='test123', port=xxx) 

Thanks

Nitin Kr

 

From: <junos-p...@googlegroups.com> on behalf of Taz <tam...@gmail.com>
Date: Thursday, 25 June 2020 at 4:38 PM
To: Junos Python EZ <junos-p...@googlegroups.com>
Subject: Juniper Script how to call Pyez using different ssh port

 

[External Email. Be cautious of content]

 

--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to junos-python-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/junos-python-ez/bf3ce68e-6ff5-46a9-8d74-e5f4a47352e8o%40googlegroups.com.


Juniper Business Use Only

Taz

unread,
Jun 25, 2020, 7:16:32 AM6/25/20
to Junos Python EZ
Thanks I have tried this but getting below error:

Traceback (most recent call last):
  File "aap001.py", line 9, in <module>
    ss.open()
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\utils\start_shell.py", line 85, in open
    self._client = open_ssh_client(dev=self._nc)
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\utils\ssh_client.py", line 40, in open_ssh_client
    ssh_client.connect(
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\client.py", line 349, in connect
    retry_on_signal(lambda: sock.connect(addr))
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\util.py", line 283, in retry_on_signal
    return function()
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\client.py", line 349, in <lambda>
    retry_on_signal(lambda: sock.connect(addr))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond





Nitin Kumar

unread,
Jun 25, 2020, 7:39:14 AM6/25/20
to Taz, Junos Python EZ

Yes, Just checked. StartShell code is using port 22 only. This was done because, PyEZ use 830 port for netconf.

Looks like startShell left it hard coded for 22. We might need to look into this.

Taz

unread,
Jun 25, 2020, 7:42:20 AM6/25/20
to Junos Python EZ
do you think there is a workaround to this ? or if its not possible. I have over 50 routers and need some way to login using all on different ports...

Any help would be much appreciated. 

Sachin Verma

unread,
Jun 25, 2020, 8:06:11 AM6/25/20
to Junos Python EZ
Hi ,

You can define mode also.Just like ..

Device(host=hostname, user=junos_username, passwd=junos_password, mode='telnet', port='23')

For SSH you can change change mode to SSH and port also.

Taz

unread,
Jun 25, 2020, 8:42:46 AM6/25/20
to Junos Python EZ
Unfortunately this didnt work either. 

I have tried 

hostname= Device(host='1.1.1.1', user='root', password='abnklh, mode= ssh, port=8021')

and also 

hostname= Device(host='1.1.1.1', user='root', password=' abnklh  , mode= ssh, port=8021')



 line 10, in <module>
    ss.open()
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\utils\start_shell.py", line 85, in open
    self._client = open_ssh_client(dev=self._nc)
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\utils\ssh_client.py", line 40, in open_ssh_client
    ssh_client.connect(
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\client.py", line 349, in connect
    retry_on_signal(lambda: sock.connect(addr))
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\util.py", line 283, in retry_on_signal
    return function()
  File "C:\Users\TAZ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\paramiko\client.py", line 349, in <lambda>
    retry_on_signal(lambda: sock.connect(addr))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Reply all
Reply to author
Forward
0 new messages