diff --git a/TP-02/scripts/run_netmiko.py b/TP-02/scripts/run_netmiko.py index 12a8412..3c54400 100644 --- a/TP-02/scripts/run_netmiko.py +++ b/TP-02/scripts/run_netmiko.py @@ -114,16 +114,34 @@ def question_20(): def question_21(): - pass + inventory = get_inventory() + + for device in inventory: + print(f"\n=== Connexion au routeur {device['hostname']} ({device['ip']}) ===") + + try: + # Connexion au routeur + net_connect = ConnectHandler( + device_type=device["device_type"], + host=device["ip"], + username=device["username"], + password=device["password"] + ) + + # Commande à exécuter + command = "show run interface GigabitEthernet0/0.99" + output = net_connect.send_command(command) + + print(f"\nConfiguration de GigabitEthernet0/0.99 sur {device['hostname']} :\n") + print(output) + + net_connect.disconnect() + + except Exception as e: + print(f"❌ Erreur sur {device['hostname']} : {e}") if __name__ == "__main__": - r01 = { - 'device_type': 'cisco_ios', - 'host': '172.16.100.126', - 'username': 'cisco', - 'password': 'cisco' - } - net_connect = ConnectHandler(**r01) + #question_9(net_connect) #question_10(net_connect) @@ -136,7 +154,7 @@ if __name__ == "__main__": #question_17(net_connect) #question_18(net_connect) hosts = get_inventory() - "print(hosts) - question_20() + print(hosts) + #question_20() #question_21() net_connect.disconnect() \ No newline at end of file