Basic script paramiko
Kita akan membuat sebuah script pyton sederhana menggunakan python untuk melakukan konfigurasi dasar pada router.
topologi masih sama seperti lab sebelumnya
Berikut script python yang kita gunakan
Ubuntu
root@NetworkAutomation-1:~# nano paramiko1.py
root@NetworkAutomation-1:~# cat paramiko1.py
import paramiko
import time
ip_address = "192.168.10.2"
username = "cisco"
password = "cisco123"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()
)
ssh_client.connect(hostname=ip_address,username=username,
password=password)
print "Success login to {0}".format(ip_address) conn =
ssh_client.invoke_shell()
conn.send("conf
t\n") conn.send("int
lo0\n")
conn.send("ip add 1.1.1.1 255.255.255.255\n")
time.sleep(1)
output =
conn.recv(65535) print
output
ssh_client.close()
Coba jalankan paramiko1.py
Ubuntu
root@NetworkAutomation-1:~# python paramiko1.py
Success login to 192.168.10.2
R1#conf t
Enter configuration commands, oneper line.End with CNTL/Z. R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#root@NetworkAutomation-1:~#
Cek pada router pastikan interface loopback sudah ada
R1
R1(config)#do show ip int brief | i up
FastEthernet0/0 ...........................192.168.10.2 YES manual up up
Loopback0 1.1.1.1 YES manual up up
seelsai
\