Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Paramiko output printing issue
#1
Here is my first ssh script, facing stdout printing issue
import socket
socket.setdefaulttimeout(5)
import paramiko
import sys
import threading
import os
import time
ip        = '10.124.117.12'
user      = 'ops'
passwd    = 'BN123'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
   ssh.connect(ip,username=user,password=passwd, timeout=5)
   print "Connected to %s" % ip
   time.sleep(5)
   connection = ssh.invoke_shell()
   stdin, stdout, stderr = ssh.exec_command("show chassis\n")
   result = stdout.read().decode('ascii').strip("\n")
   ssh.close()
   print result
except paramiko.AuthenticationException:
       print "[-] Authentication Exception! ..."
except paramiko.SSHException:
       print "[-] SSH Exception! ..." 

Error as below

python DnCollector.py
Connected to 10.124.117.188
No handlers could be found for logger "paramiko.transport"
[-] SSH Exception! ...
Quote
#2
If you let the exception propagate instead of printing SSH Exception, it will give you more information on the line that caused the trouble.
Quote
#3
import socket
socket.setdefaulttimeout(5)
import paramiko
import sys
import threading
import os
import time
ip        = '10.124.117.12'
user      = 'ops'
passwd    = 'BN123'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
   ssh.connect(ip,username=user,password=passwd, timeout=5)
   print "Connected to %s" % ip
   time.sleep(5)
   connection = ssh.invoke_shell()
   stdin, stdout, stderr = ssh.exec_command("show chassis\n")
   result = stdout.read().decode('ascii').strip("\n")
   ssh.close()
   print result
except (socket.error,paramiko.AuthenticationException,paramiko.SSHException) as message:
        print "ERROR: SSH connection to "+ip+" failed: " +str(message)
        sys.exit(1)
except paramiko.SSHException:
       print "[-] SSH Exception! ..."
showing as below error

Connected to 10.124.117.12
No handlers could be found for logger "paramiko.transport"
ERROR: SSH connection to 10.124.117.12 failed: (1, 'Administratively prohibited')
however I am able to telnet from command prompt


ssh -l ops 10.124.117.12

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! **** WARNING: UNAUTHORISED ACCESS PROHIBITED **** !
! You are about to log on to a proprietary system where access is provided, !
! by the Owner of the system, only to authorized users. !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

ops@10.124.117.12's password:

*A:BNG_01# logout
Quote
#4
import paramiko
import sys
import threading
import os
import time
ip        = '10.124.117.12'
user      = 'ops'
passwd    = 'NG123'
cmd = 'show chassis'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
   ssh.connect(ip,username=user,password=passwd, timeout=5,allow_agent=False)
   print "Connected to %s" % ip
   time.sleep(5)
   output = ''
   connection = ssh.invoke_shell()
   transport = ssh.get_transport()
   transport.set_keepalive(30)
   if connection.send_ready():
      #print ("Channel is ready")
      connection.send(cmd)
   else:
      raise("Channel not ready!")
   buff=''
   while not buff.endswith('# '): # Checking for returned prompt
         resp = connection.recv(4096)
         buff += resp
   print resp
   #stdin, stdout, stderr = ssh.exec_command(cmd)
   #result = stdout.read().decode('ascii').strip("\n")
   #paramiko.util.log_to_file("filename.log")
   #print(result)
   ssh.close()
   #print result
except (socket.error,paramiko.AuthenticationException,paramiko.SSHException) as message:
        print "ERROR: SSH connection to "+ip+" failed: " +str(message)
        sys.exit(1)

#except paramiko.AuthenticationException:
#       print "[-] Authentication Exception! ..."
except paramiko.SSHException:
       print "[-] SSH Exception! ..."
printing only below output
Connected to 10.124.117.12
*A:BNG_01#


expected output

===============================================================================
System Information
===============================================================================
Name : BNG_01
Type : 7753
Chassis Topology : Standalone
Location : Mumbai
Coordinates : (Not Specified)
CLLI code :
Number of slots : 12
Oper number of slots : 12
Number of ports : 44
Critical LED state : Off
Major LED state : Off
Minor LED state : Off
Over Temperature state : OK
Base MAC address : 40:08:7d:1f:88:01
Admin chassis mode : d
Oper chassis mode : d
Mixed mode : Disabled
Fabric Speed : 10 Gig

===============================================================================
Chassis Summary
===============================================================================
Chassis Role Status
-------------------------------------------------------------------------------
1 Standalone up
===============================================================================
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Printing output without print usage susmith552 1 350 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head
  How do I stop this fast factorization program from printing beyond the 3rd output? Pleiades 6 637 Dec-07-2019, 08:43 PM
Last Post: Pleiades
  multithreading issue with output mr_byte31 4 618 Sep-11-2019, 12:04 PM
Last Post: stullis
  Output issue twinpiques 6 745 Jul-29-2019, 11:24 PM
Last Post: Yoriz
  re.finditer issue, output is blank anna 1 581 Feb-07-2019, 10:41 AM
Last Post: stranac
  ciscolib cdp output list printing support anna 3 1,182 Jul-25-2018, 12:18 PM
Last Post: buran
  easysnmp output printing help anna 0 1,219 Apr-03-2018, 09:19 AM
Last Post: anna
  Output not printing when execute scripts in threads anna 1 1,064 Mar-21-2018, 05:08 PM
Last Post: woooee
  telnet unexpected output printing anna 3 1,510 Jan-17-2018, 01:16 PM
Last Post: anna
  Printing the output in columns pythonbabe 3 1,595 Nov-23-2017, 09:01 AM
Last Post: heiner55

Forum Jump:


Users browsing this thread: 1 Guest(s)