Python learning for Network Engineers | Part 08 | Cisco SSH using paramiko

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ:
๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง
๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ:
To stay updated with my latest videos Please subscribe to my channel by clicking below

This video will demonstrate how to initiate SSH from Python using paramiko library.
Expains classes in Paramiko, time module, getpass module
Explains about adding delay while executing commands

import paramiko
import time
from getpass import getpass

ip = '10.10.10.10'
username = 'admin'
password = 'admin'

SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SESSION.connect(ip,port=22,
username=username,
password=password,
look_for_keys=False,
allow_agent=False)

DEVICE_ACCESS = SESSION.invoke_shell()
DEVICE_ACCESS.send(b'term length 0\n')
DEVICE_ACCESS.send(b'show run\n')
output = DEVICE_ACCESS.recv(65000)

SESSION.close
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

Hi, is there any way we can know whether the command we sent has completed when we use invoke_shell ? When I use invoke_shell to send command, I have to set a timeout (sleep some time),

yiyanzhang
ะะฒั‚ะพั€

Thank you for wonderful explanation. Code match to my requirement

pranavireddy
ะะฒั‚ะพั€

๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—ณ๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€(๐Ÿญ๐Ÿฎ๐Ÿฌ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
โ˜ธ๐—ฃ๐—น๐—ฒ๐—ฎ๐˜€๐—ฒ ๐—ณ๐—ผ๐—น๐—น๐—ผ๐˜„ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—š๐—ถ๐˜๐—›๐˜‚๐—ฏ ๐—ฃ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐˜๐—ต๐—ฒ ๐—น๐—ฎ๐˜๐—ฒ๐˜€๐˜ ๐—ฐ๐—ผ๐—ฑ๐—ฒ๐˜€:
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—ก๐—ซ๐—”๐—ฃ๐—œ-๐—–๐—Ÿ๐—œ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป: ๐—ก๐—ฒ๐˜…๐˜‚๐˜€ ๐Ÿต๐—ธ :๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ฒ ๐—ท๐˜€๐—ผ๐—ป ๐—ซ๐— ๐—Ÿ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐——๐—ฎ๐˜๐—ฎ
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐˜๐—ผ ๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ฒ ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐˜‚๐˜€๐—ถ๐—ป๐—ด ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฅ๐—ฒ๐—ด๐—˜๐˜…:๐—ฟ๐—ฒ ๐—ง๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น(๐Ÿญ๐Ÿฑ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ณ๐—ฎ๐—ฐ๐—ฒ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐— ๐˜‚๐—น๐˜๐—ถ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฅ๐—ฒ๐—ด๐—˜๐˜… ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜:๐—ง๐—ฎ๐—ฏ๐˜‚๐—น๐—ฎ๐˜๐—ฒ ๐—ง๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฒ๐˜…๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ(๐Ÿฐ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—˜๐—ป๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐— ๐˜‚๐—น๐˜๐—ถ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ถ๐—ป ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด ๐—•๐—ฎ๐—ฐ๐—ธ๐˜‚๐—ฝ ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ฃ๐—ฎ๐—ฟ๐—ฎ๐—น๐—น๐—ฒ๐—น ๐—ฒ๐˜…๐—ฒ๐—ฐ๐˜‚๐˜๐—ถ๐—ผ๐—ป:๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ง๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น(๐Ÿฐ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—”๐—ป๐˜€๐—ถ๐—ฏ๐—น๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ : ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐˜๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—˜๐˜…๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ๐˜€(๐Ÿฏ๐Ÿฌ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)

NetworkEvolution
ะะฒั‚ะพั€

Hi Firstly thank you for the great videos.
I have an issue with Napalm merg/replace, when i run the code it shows that the configs have been added or not +/-, but when going onto the cisco device the configs have not chnaged. what i found is that when txt file is added to the cisco device (#dir) with the config changes.
how can i correct this so that Napalm makes the changes on the device. Quintin

quintinschnuir
ะะฒั‚ะพั€

Thanks for the guidance and great videos. Could you please help me on how to compare the network device configuration against a standard/reference configuration template?

sharathbabu
ะะฒั‚ะพั€

@NetworkEvolution


how are you getting connected to the Network devices..? can you please redirect me to that video... can you show how to connect this to the GNS3..!!

sasankt
ะะฒั‚ะพั€

Thanks for all the great videos. Do you have the git hub link to all your scripts for this series ? Please advice !

ttlhoang
ะะฒั‚ะพั€

what is the way to install paramiko in Windows without having Microsoft visual studio?

raghavank
ะะฒั‚ะพั€

sorry, when we succeed ssh connect, we have type enable password before runing command "show run" or others show command, I can't see anywhere in your code that have enable password, sorry if i get sth wrong.

dnd
ะะฒั‚ะพั€

Valuable video as usual.ย 

You used getpass to mask the password. However, the password was visible while the CLI prompted for it.

Was getpass called/invoked to even mask the password?

praveen