Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SSH connections
#1
Hi all,
im almost new in python.

I tried to get a connection to a cisco device and execute some commands, all fine here.

But my problem is that when I tried to do a second connection over ssh to a secondary device from the first one, it is not working .


my pc ---> ssh to device one ---> ssh to device two.

The reason that I need to do it like this is because the secondary device has an ACL to allow only traffic from connections came from device one.


What you suggest to get this done ?
What I need to do to get and execute commands into the secondary device?

thanks,
regards.

my code here
Reply
#2
(Jun-18-2017, 06:11 AM)Will Wrote: ...when I tried to do a second connection over ssh

What have you tried? What do you get versus what you expect?  
Quote:... it is not working
is not very helpful.  In order to improve your odds on receiving an answer, you need to post any relevant code, the output and any error codes in their entirety (all between their respective code tags. Refer to the Help Document on how to properly post and advise on how to ask a question to better ensure a response.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Sorry you are right, I forgot to put my code:

I tried this code an sometimes is working and you can get the result, but sometimes is not working, I can't understand how it is working sometimes and others not, I was playing with the clear buffers and timeouts and its appears to be affected to all the execution.
I don't knwo if this type of code is correct or not to jump from one device to another "both router cisco" in this case.

Thanks for your help.


jumpserver = {'device_type' : 'cisco_ios','ip' : ipNoc,'username':userNoc,'password' : passNoc}

for x in range(1,len(first_column)-1):
host=first_column[x].value
print("")
print (" SSH Session Established with " + ipNoc + " ....")
net_connect = ConnectHandler(**jumpserver)
print("")
print (" Interactive Session Established with " + ipNoc + " ....")
print ("")
net_connect.clear_buffer()
output=net_connect.find_prompt()
print("Trying to connecting from " + output + " to " + host +".test.net")
net_connect.clear_buffer()
net_connect.settimeout(None)
net_connect.write_channel("ssh -l "+ userAtt + " " + host +".test.net")
print("")
print (" SSH Session Established with " + host + " ....")
time.sleep(4)
net_connect.send_command('password' + "\n")
print("")
print (" Interactive Session Established with " + host + " ....")
print ("")
net_connect.clear_buffer()
net_connect.read_channel()
redispatch(net_connect, device_type='cisco_ios')
output=net_connect.find_prompt()
print(output)
output=net_connect.send_command('sh ver')
print(output)
time.sleep(timeout_modifier)
Reply
#4
You still failed to post your code between the proper code tags. As it is, it looks as if all your indentation in wrong, leaving it a guessing game as to where the 'for' loop ends, if it ever ends. Again, refer to the Help Document for instructions on how to properly post your code, output and errors
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I make this server stop listening for connections to sockets Emekadavid 0 3,385 Jun-03-2020, 02:28 PM
Last Post: Emekadavid
  Need small help on dynamic database connections Tirumal 4 3,405 Dec-28-2017, 07:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020