0% found this document useful (0 votes)
52 views3 pages

Network Automation Python Lab Practice

This document provides a practical guide for network automation using Python, featuring hands-on labs for CCNA, CCNP, and beginner engineers. It covers various tasks such as establishing SSH connections, backing up configurations, automating VLAN setups, generating interface status reports, sending email notifications, and creating configuration templates with Jinja2. The guide also includes recommended lab setups and necessary Python package installations.

Uploaded by

Shailendra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Network Automation Python Lab Practice

This document provides a practical guide for network automation using Python, featuring hands-on labs for CCNA, CCNP, and beginner engineers. It covers various tasks such as establishing SSH connections, backing up configurations, automating VLAN setups, generating interface status reports, sending email notifications, and creating configuration templates with Jinja2. The guide also includes recommended lab setups and necessary Python package installations.

Uploaded by

Shailendra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Network Automation using Python - Lab Practice

Guide
This PDF contains practical hands-on labs for Network Automation using Python. The labs are designed for CCNA,
CCNP, and beginner automation engineers. Technologies used include Python, Netmiko, Paramiko, Jinja2, and
SMTP.

Lab 1 - SSH Connection to Cisco Device

Objective: Connect to a Cisco IOS device using Python and execute show commands.
from netmiko import ConnectHandler

device = {
"device_type": "cisco_ios",
"host": "[Link]",
"username": "admin",
"password": "cisco"
}

connection = ConnectHandler(**device)

output = connection.send_command("show ip interface brief")


print(output)

[Link]()

Lab 2 - Backup Switch Configuration

Objective: Automatically backup running configuration from multiple switches.


from netmiko import ConnectHandler
from datetime import datetime

devices = ["[Link]", "[Link]"]

for ip in devices:

device = {
"device_type": "cisco_ios",
"host": ip,
"username": "admin",
"password": "cisco"
}

conn = ConnectHandler(**device)

output = conn.send_command("show running-config")

filename = f"{ip}.txt"

with open(filename, "w") as file:


[Link](output)

[Link]()

Lab 3 - VLAN Configuration Automation

Objective: Configure VLANs on Cisco switches using Python.


from netmiko import ConnectHandler

device = {
"device_type": "cisco_ios",
"host": "[Link]",
"username": "admin",
"password": "cisco"
}

commands = [
"vlan 10",
"name USERS"
]

conn = ConnectHandler(**device)

output = conn.send_config_set(commands)

print(output)

[Link]()

Lab 4 - Interface Status Report

Objective: Collect interface status from network devices.


from netmiko import ConnectHandler

device = {
"device_type": "cisco_ios",
"host": "[Link]",
"username": "admin",
"password": "cisco"
}

conn = ConnectHandler(**device)

output = conn.send_command("show interfaces status")

print(output)

[Link]()

Lab 5 - Email Network Report using SMTP

Objective: Send network reports automatically through email.


import smtplib
from [Link] import MIMEText

sender = "your_email@[Link]"
receiver = "admin@[Link]"

msg = MIMEText("Network Backup Completed Successfully")


msg["Subject"] = "Automation Report"

server = [Link]("[Link]", 587)


[Link]()

[Link](sender, "app_password")

[Link](sender, receiver, msg.as_string())

[Link]()

Lab 6 - Jinja2 Configuration Template


Objective: Generate reusable device configurations using Jinja2 templates.
from jinja2 import Template

template = '''
hostname {{ hostname }}
interface Loopback0
ip address {{ ip }} [Link]
'''

data = {
"hostname": "R1",
"ip": "[Link]"
}

j2 = Template(template)

config = [Link](data)

print(config)

Recommended Lab Setup


• Cisco IOSv / CSR1000v
• GNS3 or EVE-NG
• Python 3.x
• VS Code
• Netmiko Library

Python Package Installation


pip install netmiko
pip install paramiko
pip install jinja2

You might also like