cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
13404
Views
0
Helpful
6
Replies

Python scripts.

yaron
Level 1
Level 1

Hi all,

  Recently, I started some writing in python that I thought might be useful to some. These are still work in progress, but nevertheless. i was developing on Solaris 8 and Python 2.6.2. CiscoSwitch.py is a class which uses rshell to check things on a switch. findmap.py finds the port and switch of some MAC address. traverseall.py goes over your entire network and maps it.

  Enjoy.

-- Yaron.

6 Replies 6

Michel Hegeraat
Level 7
Level 7

Very nice of you to share this.  :-)

Tried something like this years ago in perl. My idea was to discover a netwerk using CDP but without SNMP

Had some issues because the returned CDP info was formatated different on every IOS version  :-)

If you are still developing think about including sh ip arp and sh ip ro parsing to enhance the discovery

For loop avoidance I created a record of hostname+devicetype, hoping this to be unique for each device.

Must admit that your python source looks cleaner and more readable than what I did back then in perl. But that could very well be my fault.

Cheers,

Michel

  The code is cleaner because it is in Python. I have been writing Perl for years and recently switched to Python and I can tell you that writing in Python is much easier. You think of the algorithm and simply writes it. I keep going to the Python docs for every other line and it is still much faster to write.

  I would probably add some more features to this class, but just wanted to share this, because it is already useful.

  As for ARP and routes, I am not sure I will add this because these only exists with L3 switches and the code is more into L2 switches.

Thanks for the feedback.

-- Yaron.

-- Yaron.

"michel.hegeraat" כתב:

>Michel Hegeraat created the discussion

>"Re: Python scripts."

>To view the discussion, visit: https://supportforums.cisco.com/message/3660517#3660517

Andreas Falk
Level 1
Level 1

Hi,

Thanks for the share!

This will really come in handy when batching switches..

--

Regards Falk

opnineopnine
Level 1
Level 1

Hello,

thanks for the files but I have the error ImportError: No module named CiscoSwitch

where can i download the module?

 

thanks. 

I believe you need to download all three of his packages in order to run them.   Just looking at his findmac.py script, he's got the line

4    from CiscoSwitch import CiscoSwitch

which is also referring to a script he wrote, by that name. 

In Python documentation, it mentions

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

  • the directory containing the input script (or the current directory).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • the installation-dependent default.

So the script findmac.py is looking for that script (which is presumes is named CiscoSwitch.py), and can't find it.  Did you download and extract that file to the same directory that you're running findmac.py

Review Cisco Networking for a $25 gift card