Back to Browse

Python learning for Network Engineers | Part 13 |Python3 String methods cisco device configuration

5.1K views
Mar 17, 2019
8:50

๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ: ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ: https://www.udemy.com/course/python-for-network-engineers/?referralCode=35A75AAE1ACA94A15829 Python Series Complete video Playlist URL :https://www.youtube.com/watch?v=sG_RiytUA38&list=PLOocymQm7YWakdZkBfCRIC06fv7xQE85N To stay updated with my latest videos Please subscribe to my channel by clicking below https://www.youtube.com/channel/UCcA2nhdC0wzqyv9x1lk5NnA?sub_confirmation=1 This video demostrates multiple string methods. Examples of Python 3 string methods:lstrip(), rstrip(), strip(),capitalise(),upper(),lower() import paramiko import time from getpass import getpass import datetime TNOW = datetime.datetime.now().replace(microsecond=0) username = 'admin' password = 'admin' DEVICE_LIST = open ('09_devices') for RTR in DEVICE_LIST: RTR = RTR.strip() print ('\n #### Connecting to the device ' + RTR + '####\n' ) SESSION = paramiko.SSHClient() SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy()) SESSION.connect(RTR,port=22, username=username, password=password, look_for_keys=False, allow_agent=False) DEVICE_ACCESS = SESSION.invoke_shell() DEVICE_ACCESS.send(b'terminal len 0\n') DEVICE_ACCESS.send(b'show run\n') time.sleep(5) output = DEVICE_ACCESS.recv(65000) print (output.decode('ascii')) SAVE_FILE = open('ROUTER_' + RTR , 'w') SAVE_FILE.write(output.decode('ascii')) SAVE_FILE.close SESSION.close methods and attributes of the object name1 = ' test1 ' name2 = 'test2' dir(name1) strip() is a method print (name1.lstrip()+name2) help(str) help-str strip() is a method help()- topics -STRINGS ,STRINGSMETHODS print (name2.upper()) print (name1.upper().lstrip()) capitalize(),upper()

Download

0 formats

No download links available.

Python learning for Network Engineers | Part 13 |Python3 String methods cisco device configuration | NatokHD