{"id":1702,"date":"2022-02-23T03:20:46","date_gmt":"2022-02-23T03:20:46","guid":{"rendered":"http:\/\/thechotacode.com\/?p=1702"},"modified":"2022-03-08T03:08:20","modified_gmt":"2022-03-08T03:08:20","slug":"aut","status":"publish","type":"post","link":"https:\/\/thechotacode.com\/?p=1702","title":{"rendered":"Automate Bulk Routers Configuration"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1702\" class=\"elementor elementor-1702\" data-elementor-settings=\"[]\">\n\t\t\t\t\t\t\t<div class=\"elementor-section-wrap\">\n\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ba6a86c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ba6a86c\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8e46707\" data-id=\"8e46707\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0f76a47 elementor-widget elementor-widget-text-editor\" data-id=\"0f76a47\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><!-- wp:paragraph --><\/p><p><strong><span style=\"color: #003300;\">This post basically explains about automating configuration of multiple routers which are in\u00a0 management.\u00a0<\/span><\/strong><\/p><p><strong><span style=\"color: #003300;\">There are many ways to login to the routers to perform the auto-configuration, using libraries\u00a0 like netmiko, paramiko etc&#8230;However do check if the platform that you&#8217;re using for config automation has the libraries supported for performing such operations.<\/span><\/strong><\/p><p><strong><span style=\"color: #003300;\">In my Unix server,\u00a0 I have the support of telnetlib and Paramiko libraries only, to do Telnet and SSH to the routers.<br \/>I have kept separate programs for telnet and SSH to internet routers and IPVPN routers respectively.<br \/>However, its possible to make a single program which would be able to perform both but haven&#8217;t felt the necessity yet.<\/span><\/strong><\/p><p><strong><span style=\"color: #ff0000;\"><span style=\"color: #003300;\">+++++++++++++++++<\/span><\/span><span style=\"color: #ff0000;\"><span style=\"color: #003300;\"><br \/><\/span><\/span><\/strong><strong style=\"font-size: 16px;\"><span style=\"color: #ff0000;\">Program 1 :-\u00a0 <span style=\"color: #003300;\">I&#8217;m going to explain the program in thumbnail step by step.<br \/><\/span><\/span><\/strong><span style=\"color: #ff0000;\"><span style=\"color: #003300;\">+++++++++++++++++<\/span><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step1:-\u00a0 <span style=\"color: #333300;\">These are libraries which serves like function and gives necessary output based on the input we provide in the function.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>import telnetlib\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span style=\"color: #333300;\">&lt;&lt; &#8212; helps in performing various task to perform in routers like read, write, delay of commands etc.<\/span><br \/>import getpass\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span style=\"color: #333300;\">&lt;&lt; &#8212; helps in holding passwords and take care of its storage.<\/span><\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>import sys<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>import time<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step2:- <span style=\"color: #333300;\">Used general input command to hold the username of router that you login and getpass library to hold the password.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>user = raw_input(&#8220;Enter your telnet username:- &#8220;) <\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>password = getpass.getpass()<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step3:-\u00a0<span style=\"color: #333300;\"> Sys read command will take all the routers IP and place in list. X array hold the IP&#8217;s in list.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>x = []<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>IP = sys.stdin.read()<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>x.extend(IP.strip().split(&#8216;\\n&#8217;))<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step4:-\u00a0<span style=\"color: #333300;\"> Sys read command will take all the config&#8217;s line by line and hold in list. Y array hold the config lines.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>y = []<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>Config = sys.stdin.read()<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>y.extend(Config.strip().split(&#8216;\\n&#8217;))<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step5:-\u00a0<span style=\"color: #333300;\"> There is a Nested <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> logic, the 1st <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> logic will telnet each IP in the list and 2nd <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> will loop to take each line of config and put inside the router until all the lines in the list are done, also it won&#8217;t go to the next IP.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\">for data in x:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 for a in y:<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step6:-\u00a0 <span style=\"color: #0000ff;\">&#8216;data&#8217;<\/span> <span style=\"color: #003300;\">will take each IP and will print as telnet to that IP to show us in which router it is working.<br \/>While the prompt for username and prompt is reached, the values will be called to enter for each IP.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\">print &#8220;Telnet to IP Addrecss :- &#8220;+ data<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">try:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">t = telnetlib.Telnet(data,23,20<\/span><\/strong><strong><span style=\"color: #0000ff;\">)\u00a0 \u00a0 <span style=\"color: #003300;\">&lt;&lt;&#8212; Its function calling IP in data with port number and timeout delay.<\/span><\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">t.read_until(&#8220;Username:&#8221;)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span style=\"color: #003300;\">&lt;&lt;&#8212; This read will wait for banner to complete and wait for username prompt.<\/span><\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">t.write(user + &#8220;\\n&#8221;)\u00a0 \u00a0 \u00a0<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">if password:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0 t.read_until(&#8220;Password:&#8221;)<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0 t.write(password + &#8220;\\n&#8221;)<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step7:-\u00a0 <span style=\"color: #003300;\">There could be multiple possibilities for not to login, for all such errors you will see this default message as problem to login.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>except:<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>\u00a0 \u00a0 \u00a0 print &#8220;Some issue with login please check &#8220;<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>\u00a0 \u00a0 \u00a0 pass<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step8:-\u00a0 <span style=\"color: #003300;\">Below <span style=\"color: #0000ff;\">&#8216;FOR<\/span>&#8216; is nested inside the 1st <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> for login to the IP.\u00a0 This will write through all the lines stored in &#8216;Y &#8216;array inside the router.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\">for a in y:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">\u00a0 \u00a0 t.write(str(a) + &#8216;\\n&#8217;)<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step9:-\u00a0 <span style=\"color: #003300;\">After <span style=\"color: #0000ff;\">write<\/span> command its good practice to keep a 1 sec delay before exit from router, and read operation will give all the logs in the terminal.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\"> time.sleep(1)<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">t.write(&#8220;exit\\n&#8221;)<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">print t.read_all()<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step10 OUTPUT:-\u00a0 <span style=\"color: #003300;\">If you see I have placed a inaccessible device IP 8.8.8.8, but still the program by-passes with message and progress till end.<br \/>Note:- You have to be careful with the config lines if in case of improper lines would cause issues to all device, hence its advisable to check the operations in 2 routers for testing and perform the same for all.<br \/><span style=\"color: #0000ff;\">Note:- I have tested for around 200 devices in one go so far, in putting a common snmp config.<br \/><\/span><br \/><\/span><\/strong><\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/bulk.jpg\" alt=\"\" width=\"610\" height=\"1894\" \/><\/p><p><span style=\"color: #ff0000;\"><strong>++++++++++++++++++++++<br \/>PROGRAM 2:- <span style=\"color: #333300;\">FOR SSH TO MULTIPLE DEVICES BY USING PARAMIKO LIBRARY<\/span><br \/>++++++++++++++++++++++<\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>Note:- Uptill step 4 the logic and command lines are same for fetching the input, username and password storage.<\/strong><\/span><\/p><p><strong><span style=\"color: #003300;\">The <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> Logic makes the difference in here, I will explain through in 3 steps.<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step1:-\u00a0 <span style=\"color: #003300;\">The 1st\u00a0<span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> logic will take each IP and print will display to which router is logged in to perform configuration.<\/span><br \/><span style=\"color: #003300;\">SSH will form a encrypted line to login, so there is various command\/functions to hold the key storage or username.<br \/>Timeout of 20sec if not reachable for any reason.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\">for data in x:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">print &#8220;SSH to IP Addrecss :- &#8220;+ data<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">try:<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">remote_conn_pre=paramiko.SSHClient()<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">remote_conn_pre.connect(data, port=22, username=user, password=password, timeout &#8211; 20, look_for_keys=False, allow_agent=False)<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>Step2:-\u00a0 <span style=\"color: #003300;\">During the login process, if any of the IP is not reachable for any reason then will give this default error comment and progress further.<\/span><\/strong><\/span><\/p><p><span style=\"color: #0000ff;\"><strong> except:<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>print &#8220;Some issue with login please check &#8220;<\/strong><\/span><br \/><span style=\"color: #0000ff;\"><strong>continue<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Step3:-\u00a0<span style=\"color: #003300;\"> The 2nd &#8216;<span style=\"color: #0000ff;\">FOR&#8217;<\/span>\u00a0Logic is used for putting the configs inside the router in a secure channel.<br \/>Interactive SSH session will establish by invoking shell function, ready to receive logs with terminal length 65535.<br \/>&#8216;<span style=\"color: #0000ff;\">str a<\/span>&#8216; will send each line in the array followed by enter &#8216;\\n&#8217; which is crucial in paramiko and printing the output. Kept some delay between each lines based on bandwidth it varies, followed by command &#8216;end&#8217; when all lines are executed. Once all lines are done, it will come of this <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> loop and move to the 1st <span style=\"color: #0000ff;\">&#8216;FOR&#8217;<\/span> to fetch 2nd IP and so on.<\/span><\/strong><\/span><\/p><p><strong><span style=\"color: #0000ff;\">remote_conn = remote_conn_pre.invoke_shell() remote_conn<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">output =\u00a0 remote_conn.recv(65535)<\/span><\/strong><br \/><strong><span style=\"color: #0000ff;\">print output\u00a0<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\"><br \/>for a in y:<br \/>remote_conn.send(&#8220;\\n&#8221; + str(a) )<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">time.sleep(.5)<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">output = remote_conn.recv(65535)<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">print output<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">remote_conn.send(&#8220;end\\n&#8221;)<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">time.sleep(.5)<br \/><\/span><\/strong><strong><span style=\"color: #0000ff;\">output = remote_conn.recv(65535)<\/span><\/strong><\/p><p><span style=\"color: #ff0000;\"><strong>PROGRAM:-<br \/><\/strong><\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1462 size-full\" src=\"http:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP.png\" alt=\"\" width=\"1065\" height=\"690\" srcset=\"https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP.png 1065w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-300x194.png 300w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-600x389.png 600w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-768x498.png 768w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-922x597.png 922w\" sizes=\"auto, (max-width: 1065px) 100vw, 1065px\" \/><\/p><p><strong><span style=\"color: #ff0000;\">PROGRAM OUTPUT:- <span style=\"color: #333300;\">Config handling in paramiko is so tough, I often make a lot of work around to save it.<\/span><\/span><\/strong><\/p><p><span style=\"color: #333300;\">selvara@nms4:\/home\/ip-python$ python SSH_BulkChange.py<\/span><strong><span style=\"color: #ff0000;\"><br \/><\/span><\/strong><\/p><p><span style=\"color: #333300;\">++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/span><br \/><span style=\"color: #333300;\">Enter your SSH username:- rselvaraj<\/span><br \/><span style=\"color: #333300;\">Password: <\/span><br \/><span style=\"color: #333300;\">Enter the IP&#8217;s below and press Ctrl+d <\/span><br \/><span style=\"color: #333300;\">192.168.73.100<\/span><br \/><span style=\"color: #333300;\">192.168.195.15<\/span><br \/><span style=\"color: #333300;\">8.8.8.8<\/span><br \/><span style=\"color: #333300;\">192.168.64.115<\/span><br \/><span style=\"color: #333300;\">^D<\/span><br \/><span style=\"color: #333300;\">Enter the Router Configs below and press Ctrl+d <\/span><br \/><span style=\"color: #333300;\">!<\/span><br \/><span style=\"color: #333300;\">config t<\/span><br \/><span style=\"color: #333300;\">no access-list 20<\/span><br \/><span style=\"color: #333300;\">access-list 20 permit 62.23.19.235<\/span><br \/><span style=\"color: #333300;\">!<\/span><br \/><span style=\"color: #333300;\">Snmp-server view custview mib-2.* included<\/span><br \/><span style=\"color: #333300;\">Snmp-server view custview ciscoEnvMonMIB included<\/span><br \/><span style=\"color: #333300;\">Snmp-server view custview ciscoMgmt.13 included<\/span><br \/><span style=\"color: #333300;\">Snmp-server enable traps envmon<\/span><br \/><span style=\"color: #333300;\">Snmp-server enable traps snmp<\/span><br \/><span style=\"color: #333300;\">!<\/span><br \/><span style=\"color: #333300;\">snmp-server community Ip@Cs!123 view custview RO 20<\/span><br \/><span style=\"color: #333300;\">snmp-server host 62.23.19.235 Ip@Cs!123 envmon snmp<\/span><br \/><span style=\"color: #333300;\">exit<\/span><br \/><span style=\"color: #333300;\">^D<\/span><br \/><span style=\"color: #333300;\">+++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/span><br \/><span style=\"color: #333300;\">SSH to IP Addrecss :- 192.168.73.100<\/span><br \/><span style=\"color: #333300;\">SCO000600#<\/span><br \/><span style=\"color: #333300;\">SCO000600# terminal length 0<\/span><br \/><span style=\"color: #333300;\">SCO000600#<\/span><br \/><span style=\"color: #333300;\">SCO000600#!<\/span><br \/><span style=\"color: #333300;\">SCO000600#config t<\/span><br \/><span style=\"color: #333300;\">Enter configuration commands, one per line. End with CNTL\/Z.<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#no access-list 20<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#access-list 20 permit 62.23.19.235<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#!<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#Snmp-server view custview mib-2.* included<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#Snmp-server view custview ciscoEnvMonMIB included<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#Snmp-server view custview ciscoMgmt.13 included<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#Snmp-server enable traps envmon<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#Snmp-server enable traps snmp<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#!<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#snmp-server community Ip@Cs!123 view custview RO 20<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#snmp-server host 62.23.19.235 Ip@Cs!123 envmon snmp<\/span><br \/><span style=\"color: #333300;\">SCO000600(config)#exit<\/span><br \/><span style=\"color: #333300;\">+++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/span><br \/><span style=\"color: #333300;\">SSH to IP Addrecss :- 192.168.195.15<\/span><br \/><span style=\"color: #333300;\">BER000965#<\/span><br \/><span style=\"color: #333300;\">BER000965# terminal length 0<\/span><br \/><span style=\"color: #333300;\">BER000965#<\/span><br \/><span style=\"color: #333300;\">BER000965#!<\/span><br \/><span style=\"color: #333300;\">BER000965#config t<\/span><br \/><span style=\"color: #333300;\">Enter configuration commands, one per line. End with CNTL\/Z.<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#no access-list 20<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#access-list 20 permit 62.23.19.235<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#!<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#Snmp-server view custview mib-2.* included<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#Snmp-server view custview ciscoEnvMonMIB included<\/span><br \/><span style=\"color: #333300;\">%Bad OID<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#Snmp-server view custview ciscoMgmt.13 included<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#Snmp-server enable traps envmon<\/span><br \/><span style=\"color: #333300;\">^<\/span><br \/><span style=\"color: #333300;\">% Invalid input detected at &#8216;^&#8217; marker.<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#Snmp-server enable traps snmp<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#!<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#snmp-server community Ip@Cs!123 view custview RO 20<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#snmp-server host 62.23.19.235 Ip@Cs!123 envmon snmp<\/span><br \/><span style=\"color: #333300;\">^<\/span><br \/><span style=\"color: #333300;\">% Invalid input detected at &#8216;^&#8217; marker.<\/span><br \/><span style=\"color: #333300;\">BER000965(config)#exit<\/span><br \/><span style=\"color: #333300;\">+++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/span><br \/><span style=\"color: #333300;\">SSH to IP Addrecss :- 8.8.8.8<\/span><br \/><span style=\"color: #333300;\">Some issue with login please check <\/span><br \/><span style=\"color: #333300;\">+++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/span><br \/><span style=\"color: #333300;\">SSH to IP Addrecss :- 192.168.64.115<\/span><br \/><span style=\"color: #333300;\">TRN008836#<\/span><br \/><span style=\"color: #333300;\">TRN008836# terminal length 0<\/span><br \/><span style=\"color: #333300;\">TRN008836#<\/span><br \/><span style=\"color: #333300;\">TRN008836#!<\/span><br \/><span style=\"color: #333300;\">TRN008836#config t<\/span><br \/><span style=\"color: #333300;\">Enter configuration commands, one per line. End with CNTL\/Z.<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#no access-list 20<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#access-list 20 permit 62.23.19.235<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#!<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#Snmp-server view custview mib-2.* included<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#Snmp-server view custview ciscoEnvMonMIB included<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#Snmp-server view custview ciscoMgmt.13 included<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#Snmp-server enable traps envmon<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#Snmp-server enable traps snmp<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#!<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#snmp-server community Ip@Cs!123 view custview RO 20<\/span><br \/><span style=\"color: #333300;\">TRN008836(config)#snmp-server host 62.23.19.235 Ip@Cs!123 envmon snmp<\/span><\/p><p><span style=\"color: #ff0000;\"><strong>++++++++++++++++++++++<\/strong><br \/><strong>PROGRAM 3:-\u00a0 <span style=\"color: #003300;\">What if each router need different commands to update and fetch output.<\/span><\/strong><br \/><strong>++++++++++++++++++++++<\/strong><br \/><\/span><\/p><p><span style=\"color: #0000ff;\"><strong>Note:- In programs 1 and 2 the configs were common to all devices, however if you want separate\u00a0config for each IP then it will be very complex to store each config in separate arrays and call it. However you can use file handling method, like storing the files in notepad and calling it for each devices.<\/strong><\/span><\/p><p><span style=\"color: #333300;\"><strong>In this program I would share one specific example which is possible, for every device IP there can be one command pasted in relevance to that device, its like one to one pairing of commands executed one by one. however there is a challenge in using 2 commands in relevance of that device, which I may soon come up.<\/strong><\/span><\/p><p><span style=\"color: #333300;\"><strong>Example:- If you want to find the interface name of each IP which you got, hence its just a show command to be given on each router to fetch the output.<\/strong><\/span><\/p><p><br \/><span style=\"color: #333300;\"><strong>Program:- Its similar to program 2 however there is a array calling with incremental indexing Logic.<\/strong><\/span><\/p><p><span style=\"color: #003300;\"><strong> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1462 size-full\" src=\"http:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP.png\" alt=\"\" width=\"1065\" height=\"690\" srcset=\"https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP.png 1065w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-300x194.png 300w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-600x389.png 600w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-768x498.png 768w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/SSHP-922x597.png 922w\" sizes=\"auto, (max-width: 1065px) 100vw, 1065px\" \/><\/strong><\/span><\/p><p><strong><span style=\"color: #ff0000;\">Program Output:-\u00a0<span style=\"color: #333300;\"> As you see here the interface is all loopback0. And sequence of 1st IP with 1st Command pairing is executed.<\/span><\/span><br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1464\" src=\"http:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/outputp3.png\" alt=\"\" width=\"700\" height=\"675\" srcset=\"https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/outputp3.png 590w, https:\/\/thechotacode.com\/wp-content\/uploads\/2021\/03\/outputp3-300x289.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/strong><\/p><p><strong><span style=\"color: #003300;\">You can develop one such program for telnet function, I shall try to make one program which can able to perform both telnet and SSH based on whichever is permitted in router.<\/span><\/strong><\/p><p><strong><span style=\"color: #0000ff;\">Note:- You can develop more to such program and formulate the results in notepad, excel, word as\u00a0 you wish in the output. I would explain such file handling method in coming post.<\/span><\/strong><\/p><p><span style=\"color: #003300;\"><strong>Hope you had a good learning on how the automation of configuration is carried in router. Even you can perform the logic from base machine if its accessible to managed devices.<\/strong><\/span><\/p><p><span style=\"color: #ff0000;\"><strong>Thank you for the read this far, wish you good luck!!<\/strong><\/span><\/p><p><span id=\"post-ratings-1702\" class=\"post-ratings\" data-nonce=\"72ca4f6e00\"><img decoding=\"async\" id=\"rating_1702_1\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/stars_crystal\/rating_on.gif\" alt=\"1 Star\" title=\"1 Star\" onmouseover=\"current_rating(1702, 1, '1 Star');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img decoding=\"async\" id=\"rating_1702_2\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/stars_crystal\/rating_on.gif\" alt=\"2 Stars\" title=\"2 Stars\" onmouseover=\"current_rating(1702, 2, '2 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img decoding=\"async\" id=\"rating_1702_3\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/stars_crystal\/rating_on.gif\" alt=\"3 Stars\" title=\"3 Stars\" onmouseover=\"current_rating(1702, 3, '3 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img decoding=\"async\" id=\"rating_1702_4\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/stars_crystal\/rating_on.gif\" alt=\"4 Stars\" title=\"4 Stars\" onmouseover=\"current_rating(1702, 4, '4 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img decoding=\"async\" id=\"rating_1702_5\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/stars_crystal\/rating_on.gif\" alt=\"5 Stars\" title=\"5 Stars\" onmouseover=\"current_rating(1702, 5, '5 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/> (<strong>3<\/strong> votes, average: <strong>5.00<\/strong> out of 5)<br \/><span class=\"post-ratings-text\" id=\"ratings_1702_text\"><\/span><\/span><span id=\"post-ratings-1702-loading\" class=\"post-ratings-loading\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/thechotacode.com\/wp-content\/plugins\/wp-postratings\/images\/loading.gif\" width=\"16\" height=\"16\" class=\"post-ratings-image\" \/>Loading&#8230;<\/span><!-- \/wp:paragraph --><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>This post basically explains about automating configuration of multiple routers which are in\u00a0 management.\u00a0 There are many ways to login to the routers to perform the auto-configuration, using libraries\u00a0 like netmiko, paramiko etc&#8230;However do check if the platform that you&#8217;re using for config automation has the libraries supported for performing such operations. In my Unix&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1702","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codes","wpcat-10-id"],"_links":{"self":[{"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/posts\/1702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thechotacode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1702"}],"version-history":[{"count":7,"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/posts\/1702\/revisions"}],"predecessor-version":[{"id":2299,"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/posts\/1702\/revisions\/2299"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thechotacode.com\/index.php?rest_route=\/wp\/v2\/media\/1360"}],"wp:attachment":[{"href":"https:\/\/thechotacode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thechotacode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thechotacode.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}