I don’t have personal experience with Mac PCs, but I am under the impression that GNS3 does run well on Mac OS X. Take a look at this post on GNS3’s site concerning how to set that up:
There are various other options for Macs including EVE-NG which has comprehensive API documentation and from what I read, it does support Mac environments.
The other tools necessary to get this to work is the use of an API Platform like Postman, which is also available for Mac.
Once you get those running on your Mac, you can then view the configuration process and the code involved in logging on using SSH which can be found in the following lesson:
When using Paramiko and the ssh.exec_command function, it contains what are known as three data streams. These are the input, the output, and any errors that may appear. This is known as a 3-tuple. The syntax is:
You can use any variable names you like in place of stdin, stdout, and stderr.
All three of these streams are returned whenever the ssh.exec_command function is executed and they contain the following information:
stdin - the input stream. This contains the actual commands that were sent
stdout - the output stream. This contains the output that the CLI returns in response to the command
stderr - any errors that may have appeared are stored herre.
These streams act as standard Python object files and can be manipulated as such. That’s why in the lesson, you see a command such as output = ssh_stdout.readlines().
I believe that the problem is that you’re issuing the command show systemip. However, this command doesn’t exist on a Cisco IOS device, so the result will be an error. That means that the output will be sent through the ssh_stderr stream. Try looking at the output of ssh_stderr to see if you get anything there.
I should have mentioned this is not a Cisco device, sorry for such confusion.
I have checked ssh_stderr as well - it’s empty. Also, I tried to get output from the device by the Pexpect module and it works fine.
I think Paramiko cannot help me here with my device (not sure what is exact difference b\w Paramiko and Pexpect).
Thanks for the clarification! Hmm, that does seem strange indeed. There should be some response, whether an error or not, but in any case, I’m not sure what the behavior is when connected to a non-cisco device.
Pexpect is a similar tool to Paramiko in that it allows for the automation of interactive applications such as SSH.
Paramiko is a Python implementation of SSH, and version 2 specifically, and can provide both client and server functionality. Pexpect on the other hand is a module that supports a much broader range of communication protocols including FTP, Telnet and others. For the most part, Pexpect is a superset of Paramiko but requires more parameterization.
It means the code ran without any errors. If it does have errors, it shows exit code 1.
You should however also see messages from when you use the print function in your code. It’s been a while since I used Pycharm, but by default, it should show whatever you “print” on your console.
You can try debugging your code:
This is an example for vscode but it works similarly on Pycharm. If you are new to Python, I would also recommend to start with vscode instead of Pycharm. Vscode is a light weight IDE and easier to become familiar with.
Would you mind adding topic to teach nornir framework in the course ? it seems getting popular day by day as a Framework the way it helps to manage larger inventory for hyperscale automation.
Thanks for your suggestion! It would be a good idea to share your suggestion on the following Member Ideas page.
There you will find that others may have suggested something similar, and you can add your voice to theirs. IN the meantime, take a look at this Cisco information about nornir:
Hello - Rene and dear staff - this is not a question - just an expression of gratitude
After completing your Ptyhon course, i was able to incorporate many elements you taught us into the following script:
import paramiko
device_ip = input("Enter IP of device: ")
device_username = input("Enter your username: ")
device_password = input("Enter your password: ")
cli_command = input("Enter your command: ")
ssh = paramiko.SSHClient()
def connect_to_device(ip,username,password,command):
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip,
username=username,
password=password,
look_for_keys=False )
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(command)
output = ssh_stdout.readlines()
ssh.close()
return output
except:
print("Unable to connect")
output = connect_to_device(device_ip,device_username,device_password,cli_command)
if output != None:
for line in output:
line=line.strip()
print(line)
It dynamically asks for credentials /device information/command feed them into function and print a neat show output!
The script is also designed to handle errors
Im really thrilled to reach this point - thanks to your lessons !
ps - im not able to recreate the indentation in the post - but it works , next up: retrieve IPs from a file
Thank you so much for sharing your results with us, and for your kind words. We’re thrilled that the lessons have been so useful to you! We hope that the site continues to be an important resource in your endeavors.