import paramiko
import time
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox
import logging
from datetime import datetime
# Configure logging to file
log_filename = f"ise_config_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
logging.basicConfig(
filename=log_filename,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s"
)
# Saved profiles
PROFILES = {
"Cisco DevNet Sandbox": {
"username": "readonly,
"password": "ISEisC00L"
},
"Local Test Server": {
"host": "127.0.0.1",
"username": "admin",
"password": "admin123"
}
}
def ssh_to_ise_and_configure(host, username, password, output_box, progress_bar😞
try:
progress_bar["value"] = 30
output_box.insert(tk.END, f"Connecting to {host}...\n")
logging.info(f"Connecting to {host}...")
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(host, username=username, password=password, timeout=30)
output_box.insert(tk.END, "Connection established!\n")
logging.info("Connection established.")
progress_bar["value"] = 30
shell = ssh_client.invoke_shell()
time.sleep(1)
shell.send("application configure ise\n")
time.sleep(2)
output = shell.recv(65535).decode('utf-8')
output_box.insert(tk.END, output + "\n")
logging.info(output)
progress_bar["value"] = 50
if "Select" in output:
shell.send("16\n")
time.sleep(2)
output = shell.recv(65535).decode('utf-8')
output_box.insert(tk.END, output + "\n")
logging.info(output)
progress_bar["value"] = 70
shell.send("0\n")
time.sleep(2)
output = shell.recv(65535).decode('utf-8')
output_box.insert(tk.END, output + "\n")
logging.info(output)
ssh_client.close()
output_box.insert(tk.END, "Configuration completed and connection closed.\n")
logging.info("Configuration completed and connection closed.")
progress_bar["value"] = 100
except paramiko.AuthenticationException:
messagebox.showerror("Authentication Error", "Invalid username or password.")
logging.error("Authentication failed.")
except paramiko.SSHException as ssh_error:
messagebox.showerror("SSH Error", str(ssh_error))
logging.error(f"SSH error: {ssh_error}")
except Exception as e:
messagebox.showerror("Error", str(e))
logging.error(f"Unexpected error: {e}")
def launch_gui():
window = tk.Tk()
window.title("Cisco ISE Configurator")
# Profile dropdown
tk.Label(window, text="Profile:").grid(row=0, column=0, sticky="e")
profile_var = tk.StringVar()
profile_dropdown = ttk.Combobox(window, textvariable=profile_var, values=list(PROFILES.keys()), state="readonly", width=40)
profile_dropdown.grid(row=0, column=1)
profile_dropdown.current(0)
# Output box
output_box = scrolledtext.ScrolledText(window, width=80, height=20)
output_box.grid(row=3, column=0, columnspan=2, padx=10, pady=10)
# Progress bar
progress_bar = ttk.Progressbar(window, orient="horizontal", length=400, mode="determinate")
progress_bar.grid(row=4, column=0, columnspan=2, pady=10)
# Button
def on_connect():
profile = PROFILES[profile_var.get()]
output_box.delete(1.0, tk.END)
progress_bar["value"] = 0
ssh_to_ise_and_configure(profile["host"], profile["username"], profile["password"], output_box, progress_bar)
connect_button = tk.Button(window, text="Connect & Configure", command=on_connect)
connect_button.grid(row=2, column=0, columnspan=2, pady=10)
window.mainloop()
if __name__ == "__main__":
launch_gui()