Automation, Basic Script Paramiko
Dilanjut dari lab sebelumnya, kali ini kita akan mencoba menambahkan IP loopback secara otomatis kedalam router lewat script phyton.
Berikut scriptnya:
ip_address =
"192.168.10.2" username
= "fathan"
password = "fathanrafaa"
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()
Dan untuk menginputnya masukkan di ubuntu:
root@NetworkAutomation-1:~# nano
paramiko1.py root@NetworkAutomation-1:~# cat paramiko1.py import paramiko import time
ip_address =
"192.168.10.2" username
= "fathan"
password = "fathanrafaa"
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()
Jika sudah coba kita jalankan
root@NetworkAutomation-1:~# python paramiko1.py Success login to 192.168.10.2
R1#conf t
Enter configuration commands, one per line.End with CNTL/Z.
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
Disini router akan secara otomatis mengetik sendiri.
Jika sudah kita cek di router
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
Yup IP loopback sudah hadir
Komentar
Posting Komentar