ScreenOS Firewalls (NOT SRX)
Highlighted
ScreenOS Firewalls (NOT SRX)

Python Paramiko with netscreen

‎07-27-2016 01:21 AM

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.

Regards,
Mohamed Elhariry
2* JNCIE (SEC # 159, SP # 1059),JNCIP-ENT

[Click the "Star" for Kudos if you think I earned it!
If this solution worked for you please flag my post as an "Accepted Solution" so others can benefit..]
2 REPLIES 2
Highlighted
ScreenOS Firewalls (NOT SRX)

Re: Python Paramiko with netscreen

‎07-27-2016 03:15 AM

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.

Steve Puluka BSEET - Juniper Ambassador
IP Architect - DQE Communications Pittsburgh, PA (Metro Ethernet & ISP)
http://puluka.com/home
Highlighted
ScreenOS Firewalls (NOT SRX)

Re: Python Paramiko with netscreen

‎07-27-2016 03:25 AM

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

Regards,
Mohamed Elhariry
2* JNCIE (SEC # 159, SP # 1059),JNCIP-ENT

[Click the "Star" for Kudos if you think I earned it!
If this solution worked for you please flag my post as an "Accepted Solution" so others can benefit..]
Feedback