06-14-2012 01:41 PM
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.
06-15-2012 12:33 AM
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
06-15-2012 03:19 AM
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.
06-18-2012 06:19 AM
10-03-2012 06:14 AM
Hi,
Thanks for the share!
This will really come in handy when batching switches..
--
Regards Falk
01-25-2018 07:40 AM
Hello,
thanks for the files but I have the error ImportError: No module named CiscoSwitch
where can i download the module?
thanks.
09-11-2018 03:06 AM
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:
PYTHONPATH
(a list of directory names, with the same syntax as the shell variable PATH
).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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide