Automation Network: 4. Multi Script Python dengan Mikrotik dan Cisco

33 sec read

script ini menggabungkan automation dua device berbeda menggunakan mikrotik dan cisco secara bersamaan

import paramiko
import time

# router = str(input("Masukan jenis router: "))
devices = [
    {
        'vendor'        :   'cisco',
        'ip_address'    :   '192.168.5.3',
        'username'      :   'cisco',
        'password'      :   'cisco',
    },
    {
        'vendor'        :   'mikrotik',
        'ip_address'    :   '192.168.5.2',
        'username'      :   'admin',
        'password'      :   '',
    },
]

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)



for device in devices:
    
    ssh_client.connect(hostname=device['ip_address'],username=device['username'],password=device['password'], allow_agent=False, look_for_keys=False)
    print("\nSuccess login to {}".format(device['ip_address']))

    if device['vendor'] == 'cisco':
        conn = ssh_client.invoke_shell()

        conn.send("conf t\n")
        conn.send("int lo2\n")
        conn.send("ip add 10.1.1.3 255.255.255.255\n")
        conn.send("do show ip int br")
        time.sleep(1)

        output = conn.recv(65535)
        print(output.decode())
    else:
        ssh_client.exec_command("interface bridge add name=loopback1\n")
        ssh_client.exec_command("ip address add address 10.2.2.2/32 interface=loopback1\n")      
        

    ssh_client.close()

hasilnya

How to Run Django on Jupyter Notebook Visual Code

previously I have struggled to debug my app when running Python app directly; I need it to run on my Jupyter Workspace easily to...
admin
27 sec read

How to secure important data with environments in Python

python file .env
admin
19 sec read

Custome Setting Database Django

berikut ini macam cara settting database django MAMP Server 2. MYSQL Server (XAMPP) 3. Default
admin
13 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *