cancel
Showing results for 
Search instead for 
Did you mean: 

python script to create logon banner

python script to create logon banner

robot71
New Contributor

Hello I have tried creating multiple python scripts to create a logon banner for a EXOS Switch. I can do it manually via serial easily, But when I try to automate using a script it keeps failing for the banner comes up blank. What I am doing wrong? Below is a example script of I have been using. I would appreciate any help or feedback. if anyone has an example script that would be very useful as well. I have removed the IPs, username and passwords.

 

# Import the netmiko library for SSH connections
from netmiko import ConnectHandler

# Define the devices list with the host, device_type, username, and password
devices = [
    {
        "host": "",
        "device_type": "extreme_exos",
        "username": "",
        "password": ""
    },
    {
        "host": "",
        "device_type": "extreme_exos",
        "username": "",
        "password": ""
    }
]

# Define the banner string to be displayed before login
banner = "WARNING: This device is part of the Network. Access to this device is restricted to authorized personnel only. Unauthorized access or use of this device may result in disciplinary action, civil liability, or criminal prosecution. All activity on this device is subject to monitoring and recording. By accessing this device, you consent to such monitoring and recording and agree to comply with the Alonso Network Acceptable Use Policy (AUP). If you do not agree, disconnect immediately."

# Loop through each device in the devices list
for device in devices:
    # Create a SSH connection to the device
    ssh_conn = ConnectHandler(**device)
    # Print the device hostname
    print(f"Connected to {ssh_conn.find_prompt()}")
    # Send the configure banner before-login command with the banner string
    ssh_conn.send_config_set(f"configure banner before-login\n{banner}\n")
    # Save the configuration
    ssh_conn.save_config()
    # Close the SSH connection
    ssh_conn.disconnect()
    # Print a confirmation message
    print(f"Banner configured and saved on {device['host']}")

2 ACCEPTED SOLUTIONS

katherine561
New Contributor

Your Python script for setting an EXOS switch login banner using netmiko looks generally correct. However, ensure that the "device_type" is specified as "extreme_exos," and after establishing an SSH connection, use the appropriate EXOS command (configure banner motd) to set the login banner. After sending the banner text, save the configuration with write memory for the changes to take effect. Test the script in a safe environment before applying it in production, adhering to your organization's procedures for network configuration changes.

View solution in original post

robot71
New Contributor

configure banner before-login is the command for EXOS Though. configure banner motd is for Cisco

View solution in original post

2 REPLIES 2

robot71
New Contributor

configure banner before-login is the command for EXOS Though. configure banner motd is for Cisco

katherine561
New Contributor

Your Python script for setting an EXOS switch login banner using netmiko looks generally correct. However, ensure that the "device_type" is specified as "extreme_exos," and after establishing an SSH connection, use the appropriate EXOS command (configure banner motd) to set the login banner. After sending the banner text, save the configuration with write memory for the changes to take effect. Test the script in a safe environment before applying it in production, adhering to your organization's procedures for network configuration changes.

GTM-P2G8KFN