Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Netmiko Loop question
#3
I was able to get this to work. Prompts for IP Address and switchport number. Not as elegant as automatically running for all "up" interfaces, but it will have to do for now. I'll keep playing and learning with loops.

I added the global delay of 7 seconds to wait between the running of the "test cable tdr int x" and the "show cable tdr int x".

Maybe this will help someone down the road.

Well, back to reading more on python loops and nested loops.

Cheers!



#!/usr/bin/env python

from netmiko import Netmiko
from netmiko import ConnectHandler
import time
import re

ipaddr = input ('Enter the IP: ')
interface = input ('Enter the switchport number to be tested: ')

cisco = {
'device_type': 'cisco_ios',
'host': ipaddr,
'username': 'cisco',
'password': 'cisco',
'timeout': 35 * 60,
'global_delay_factor': 7,
}


net_connect = ConnectHandler(**cisco)

output1 = net_connect.send_command('test cable tdr int ' + interface)

output2 = net_connect.send_command('sh cable tdr int ' + interface)
print()
print('TDR TEST RESULTS FOR INTERFACE: ')
print()
print(output2)
Reply


Messages In This Thread
Netmiko Loop question - by sc00ter - Oct-24-2020, 09:09 PM
RE: Netmiko Loop question - by sc00ter - Oct-24-2020, 09:21 PM
RE: Netmiko Loop question - by sc00ter - Oct-24-2020, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have an issue with Netmiko Error reading SSH protocol banner omarhegazy 2 3,513 May-16-2022, 06:05 PM
Last Post: omarhegazy
  A question about 'Event loop is closed' fc5igm 2 2,165 Oct-05-2021, 02:00 AM
Last Post: fc5igm
Exclamation question about input, while loop, then print jamie_01 5 2,616 Sep-30-2021, 12:46 PM
Last Post: Underscore
  for loop question KEYS 1 1,697 Oct-27-2020, 11:42 PM
Last Post: jefsummers
  while loop question KEYS 2 1,976 Sep-26-2020, 11:02 PM
Last Post: KEYS
  New to programming, loop question tomyan 1 1,596 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  while loop question spalisetty06 2 1,814 Aug-13-2020, 04:18 PM
Last Post: buran
  question about for loop Than999 5 2,428 Jun-09-2020, 02:16 PM
Last Post: Emekadavid
  Sending Advanced Commands with Netmiko rogueakula 1 1,974 Oct-22-2019, 07:54 PM
Last Post: rogueakula
  Question about for loop not creating an infinite loop. FWendeburg 1 2,085 Feb-03-2019, 08:45 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020