Automation Lab2 (Python OSPF Script) v3
Automation Lab2 (Python OSPF Script) v3
Topology Diagram
Task
TASK: Configure OSPF & below parameters on R1 & R2 using Python script through Local PC.
R1 should be able to ping R2 after your configuration.
1 www.networkwalks.com info@networkwalks.com
‐ Configure Loopback0 on R2 with IP: 2.2.2.2 /32
‐ OSPF Process ID on both R1 & R2: 1
The IP addresses on Router interface fa0/0 & your local PC are shown in the topology above
Solution
1. Configure local Loopback on your Laptop (follow the guide shared with you separately
for this)
2. Configure below IP address & subnet mask on this local loopback interface:
2 www.networkwalks.com info@networkwalks.com
3. Prepare R1 to be accessed via Telnet from our Local PC/Laptop
These steps are necessary for preparing the Router to be accessed via Telnet from our Local PC/Laptop.
3 www.networkwalks.com info@networkwalks.com
nw_R2(config)# ip address 192.168.1.3 255.255.255.0
5. Run the following Python Script in the interpreter (Pycharm is used in this lab)
Enter username & password as configure in above step#3 & 4
Username: john
Password: nw
Instructor will explain to you each line of code in below & guide you on each step
import getpass
import sys
import telnetlib
#R1
4 www.networkwalks.com info@networkwalks.com
user = input("Enter your telnet username for R1:")
password = getpass.getpass()
tn = telnetlib.Telnet("192.168.1.1")
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"enable\n")
tn.write(b"conf t\n")
tn.write(b"hostname nw_Router1\n")
tn.write(b"exit\n")
tn.write(b"exit\n")
tn.write(b"logout\n")
print(tn.read_all().decode('ascii'))
5 www.networkwalks.com info@networkwalks.com
#R2
password = getpass.getpass()
tn = telnetlib.Telnet("192.168.1.3")
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"enable\n")
tn.write(b"conf t\n")
tn.write(b"hostname nw_Router2\n")
tn.write(b"exit\n")
tn.write(b"exit\n")
6 www.networkwalks.com info@networkwalks.com
tn.write(b"logout\n")
print(tn.read_all().decode('ascii'))
Verification
7 www.networkwalks.com info@networkwalks.com
7. Check on R1 whether R2 is an OSPF neighbor or not
8 www.networkwalks.com info@networkwalks.com
9. Ping R1’s Loopback from R2:
References / Comments
*Please follow the below important points to avoid errors in opening the attached GNS3 topology:
✓ The image name should match (c7200-adventerprisek9-mz.152-4.S7.image)
✓ The Local Loopback Interface name should match (Local LB NW)
9 www.networkwalks.com info@networkwalks.com