Mục tiêu thực hành:
- Cấu hình telnet server trên Cisco Router.
- Biên soạn file telnet.py bằng notepad trên Window 10.
- Tiến hành copy file telnet.py lên CentOS bằng WinSCP.
- Tiến hành cài đặt Netmiko API và gói cisco-telnet.git trên CentOS.
- Tiến hành chạy script telnet.py trên CentOS.
Các bước triển khai:
Cấu hình telnet server trên Cisco Router.
hostname Routerenable password ciscousername cisco password ciscoline vty 0 4login localtransport input allexit
Biên soạn file telnet.py bằng notepad trên Window 10.
import getpassimport sysimport telnetlibHOST = "192.168.100.249"user = input("Enter your remote account: ")password = getpass.getpass()tn = telnetlib.Telnet(HOST)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"cisco\n")tn.write(b"show arp\n")tn.write(b"exit\n")print(tn.read_all().decode('ascii'))
Tiến hành copy file telnet.py lên CentOS bằng WinSCP.
- Kéo file telnet.py từ trái sang phải để tiến hành copy.
Tiến hành cài đặt Netmiko API và gói cisco-telnet.git trên CentOS.
- Cài đặt Netmiko API.
python3.8 -m pip install netmikopython3.8 -m pip install --upgrade pip netmiko
- There is a python library on github, specifically for telneting to cisco devices.
pip install git+https://github.com/sergeyzelyukin/cisco-telnet.git
Tiến hành chạy script telnet.py trên CentOS.
[root@localhost Python-3.8.2]# cd /opt/Python-3.8.2[root@localhost Python-3.8.2]# python telnet.pyEnter your remote account: ciscoPassword:Router>enablePassword:Router#show arpProtocol Address Age (min) Hardware Addr Type InterfaceInternet 192.168.100.237 16 80ce.6282.7f9f ARPA Ethernet0/1Internet 192.168.100.248 5 000c.2978.335f ARPA Ethernet0/1Internet 192.168.100.249 - aabb.cc00.0510 ARPA Ethernet0/1Internet 192.168.100.254 0 e055.3d8e.c978 ARPA Ethernet0/1Router#exit[root@localhost Python-3.8.2]#
Mọi thắc mắc các bạn vui lòng liên hệ với mình thông qua kênh Zalo (Jade Bùi) 076.877.2021.
0 comments