<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python script to change/update hostname's of multiple Cisco devices. in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421222#M2285</link>
    <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/502496"&gt;@shivshankarjalanila&lt;/a&gt;&amp;nbsp;: Check if it helps&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://thwack.solarwinds.com/product-forums/network-configuration-manager-ncm/f/forum/55733/hostname-change-in-multiple-cisco-devices" target="_blank"&gt;https://thwack.solarwinds.com/product-forums/network-configuration-manager-ncm/f/forum/55733/hostname-change-in-multiple-cisco-devices&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 15:32:59 GMT</pubDate>
    <dc:creator>inderdeeps</dc:creator>
    <dc:date>2021-06-21T15:32:59Z</dc:date>
    <item>
      <title>Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421213#M2284</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It will be very helpful if someone can help with a script (preferably Python) using which I can change/update the hostnames of multiple Cisco devices instead of doing it one by one manually.&lt;/P&gt;&lt;P&gt;I already have the hostname configured just need to update the hostname across 100s of Cisco devices to maintain the standards.&lt;/P&gt;&lt;P&gt;Please note, I am very new to automation and for now, I only know how to SSH into Cisco devices using Python+Netmiko.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Shiv&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:20:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421213#M2284</guid>
      <dc:creator>shivshankarjalanila</dc:creator>
      <dc:date>2021-06-21T15:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421222#M2285</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/502496"&gt;@shivshankarjalanila&lt;/a&gt;&amp;nbsp;: Check if it helps&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://thwack.solarwinds.com/product-forums/network-configuration-manager-ncm/f/forum/55733/hostname-change-in-multiple-cisco-devices" target="_blank"&gt;https://thwack.solarwinds.com/product-forums/network-configuration-manager-ncm/f/forum/55733/hostname-change-in-multiple-cisco-devices&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:32:59 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421222#M2285</guid>
      <dc:creator>inderdeeps</dc:creator>
      <dc:date>2021-06-21T15:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421227#M2286</link>
      <description>&lt;P&gt;Here is Pythion script easy to understand and simple to replace what you like to replace on the devices :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/grelleum/youtube-network-automation" target="_blank"&gt;https://github.com/grelleum/youtube-network-automation&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;check the youtube, his series simple, in hours time you can do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:37:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421227#M2286</guid>
      <dc:creator>balaji.bandi</dc:creator>
      <dc:date>2021-06-21T15:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421265#M2287</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/284100"&gt;@inderdeeps&lt;/a&gt;, Thank you for your response.&amp;nbsp;I am looking for something simple to understand.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:38:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421265#M2287</guid>
      <dc:creator>shivshankarjalanila</dc:creator>
      <dc:date>2021-06-21T16:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421267#M2288</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/286878"&gt;@balaji.bandi&lt;/a&gt;, Thank you for your response.&lt;/P&gt;&lt;P&gt;I went through few initial videos. It seems simple and interesting. Let me go through all and see if I find the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Shiv&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:40:28 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421267#M2288</guid>
      <dc:creator>shivshankarjalanila</dc:creator>
      <dc:date>2021-06-21T16:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421271#M2289</link>
      <description>&lt;P&gt;if you see all 9 or 10 videos, you become python network programmer can do day to day task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:46:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4421271#M2289</guid>
      <dc:creator>balaji.bandi</dc:creator>
      <dc:date>2021-06-21T16:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco devices.</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4425395#M2290</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Try the following:&lt;/P&gt;
&lt;PRE&gt;#!/usr/bin/env python3
import getpass
import csv
import netmiko
import paramiko
from argparse import ArgumentParser


def main():
    parser = ArgumentParser(description='Arguments for running oneLiner.py')
    parser.add_argument('-c', '--csv', required=True, action='store', help='Location of CSV file')
    args = parser.parse_args()

    ssh_username = input("SSH username: ")
    ssh_password = getpass.getpass('SSH Password: ')

    with open(args.csv, "r") as file:
        reader = csv.DictReader(file)
        for device_row in reader:
            try:
                ssh_session = netmiko.ConnectHandler(device_type='cisco_ios', ip=device_row['device_ip'],
                                                     username=ssh_username, password=ssh_password)

                print("+++++ {0} +++++".format(device_row['device_ip']))
                commands = ["hostname {0}".format(device_row['new_hostname'])]
                ssh_session.enable()
                ssh_session.send_config_set(commands)
                ssh_session.send_command("wr mem")
                ssh_session.disconnect()

            except (netmiko.ssh_exception.NetMikoTimeoutException,
                    netmiko.ssh_exception.NetMikoAuthenticationException,
                    paramiko.ssh_exception.SSHException) as s_error:
                print(s_error)


if __name__ == "__main__":
    main()&lt;/PRE&gt;
&lt;P&gt;You will need to feed it a csv file with the following format:&lt;/P&gt;
&lt;PRE&gt;device_ip,new_hostname&lt;BR /&gt;192.168.1.1,new_host01
192.168.1.2,new_host02
192.168.1.3,new_host03&lt;/PRE&gt;
&lt;PRE&gt;# python3 -c new_hostnames.csv&lt;/PRE&gt;
&lt;P&gt;The script will prompt you for a username and password and will use those credentials for every device in the csv file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 12:52:12 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/4425395#M2290</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2021-06-29T12:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to change/update hostname's of multiple Cisco device</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/5201782#M2738</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;Thank you everyone for the help and pointers.&lt;/P&gt;&lt;P&gt;I completed the task using the script and prerequisite points mentioned below.&lt;/P&gt;&lt;P&gt;1. I ran Python on a Windows laptop.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;&lt;SPAN&gt;Used a &lt;FONT color="#3366FF"&gt;&lt;EM&gt;SwitchIPList&lt;/EM&gt;&lt;/FONT&gt;.txt file.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. I used the below script.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Task accomplished.&lt;/P&gt;&lt;P&gt;I have added a lot of separators, you can edit/remove them.&lt;/P&gt;&lt;P&gt;Below is the script that executed repetitive commands on multiple network nodes. I hope it helps.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from netmiko import ConnectHandler
from getpass import getpass
#import sys

#SSH to multpile devices
#create device template
with open("SwitchIPList.txt") as switches:
    for IP in switches:
        Switch = {
            "device_type": "cisco_ios",
            "ip": IP,
            "username": input("Username: "),
            "password": getpass(),
#            "username": "",
#            "password": "",
        }
        net_connect = ConnectHandler(**Switch)
############################## Connect to IP ##############################
        print("*"*90)
        print ("Connecting to " + IP)
        print("*"*90)
############################## show commands ##############################
        output = net_connect.send_command("show run | s aaa group|radius server")
        print(output)
        print("-"*72)
############################## Config radius server ##############################
        config_commands = ["radius server naca001.nac.com\n",
                            "address ipv4 10.200.0.1 auth-port 1812 acct-port 1813\n",
                            "automate-tester username GNSRADIUS idle-time 10\n",
                            "key YourPassword\n",
                            "!\n",
                            "radius server naca002.nac.com\n",
                            "address ipv4 10.200.0.2 auth-port 1812 acct-port 1813\n",
                            "automate-tester username GNSRADIUS idle-time 10\n",
                            "key YourPassword\n",
                            "!\n",
                                                        	]
        output = net_connect.send_config_set(config_commands)
        print(output)
        print("-"*72)
        output = net_connect.send_command("show run | s aaa group|radius server")
        print(output)
        print("-"*72)
############################## Test NAC ##############################
        print("+"*10,"Test to radius server naca001.nac.com - 10.200.0.1","+"*10)
        output = net_connect.send_command("test aaa group NAC-V2 test test legacy")
        print(output)
        print("-"*72)
        output = net_connect.send_command("wr")
        print(output)
        print("-"*72)
        print("="*27,"END OF SWITCH","="*27)
        
#Close the connection
net_connect.disconnect()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Shiv&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Oct 2024 13:28:00 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-change-update-hostname-s-of-multiple-cisco/m-p/5201782#M2738</guid>
      <dc:creator>shivshankarjalanila</dc:creator>
      <dc:date>2024-10-01T13:28:00Z</dc:date>
    </item>
  </channel>
</rss>

