Screen OS

last person joined: 8 months ago 

This is a legacy community with limited Juniper monitoring.
  • 1.  Python Paramiko with netscreen

    Posted 07-27-2016 01:21

    Hello,

     

    I am trying to use python script to connect to netscreen firewall using paramiko and grap some commands output. It works fine with Juniper SRX, however it is not working on netscreen. If any solution or alternative script can be used please let me know

     

    import paramiko

    List = ['10.1.1.1']

    for router in List:
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.load_system_host_keys()
    client.connect(router, username='netscreen',password='netscreen')
    print '\n' + '\n' + "[-] SSH connection established successfully to %s" % router + '\n'
    stdin, stdout, stderr = client.exec_command("get config")
    data = stdout.read()
    print data
    client.close()

     

    -------------------------------

     

    OUTPUT

     

    [-] SSH connection established successfully to 10.1.1.1

    Traceback (most recent call last):
    File "E:\ssh.py", line 12, in <module>
    stdin, stdout, stderr = client.exec_command("get config")
    File "C:\Python27\lib\site-packages\paramiko\client.py", line 418, in exec_com
    mand
    chan.exec_command(command)
    File "C:\Python27\lib\site-packages\paramiko\channel.py", line 60, in _check
    return func(self, *args, **kwds)
    File "C:\Python27\lib\site-packages\paramiko\channel.py", line 234, in exec_co
    mmand
    self._wait_for_event()
    File "C:\Python27\lib\site-packages\paramiko\channel.py", line 1103, in _wait_
    for_event
    raise e
    paramiko.ssh_exception.SSHException: Channel closed.



  • 2.  RE: Python Paramiko with netscreen

    Posted 07-27-2016 03:16

    I would start by trying a smaller return command.  The get config returns a lot of data. This is only one line.

     

    get domain

     

    This will help determine if the issue is command specific or general.



  • 3.  RE: Python Paramiko with netscreen

    Posted 07-27-2016 03:25

    I manage to fixed after changed my code

     

    remote_conn_pre = paramiko.SSHClient()
    remote_conn_pre.set_missing_host_key_policy(
    paramiko.AutoAddPolicy())
    remote_conn_pre.connect(ip, username=username, password=password)
    print '\n' + '\n' + "[-] SSH connection established successfully to %s" % ip + '\n'
    remote_conn = remote_conn_pre.invoke_shell()
    remote_conn.send('get hostname\n')
    time.sleep(2)
    output = remote_conn.recv(1048576)
    print output