Parse cisco's "show ip route" output in Python 2.7

Dan Stromberg drsalists at gmail.com
Sun Mar 4 19:47:46 EST 2012


I've done little with Ciscos,  but what if you use individual things like
 "show ip ospf", "show ip rip database", etc. instead of "show ip route".
Does that makes things a little more consistent?

Often big problems are simpler if we can divide them into smaller, more
manageable subproblems.

On Sun, Mar 4, 2012 at 4:20 PM, Antgoodlife <antgoodlife at gmail.com> wrote:

> Hi All,
>
> Long time reader, first time poster.  I'm trying to parse the output
> of the SHOW IP ROUTE command from a cisco router (It's a 3800 Series
> IOS 12.4 although almost all should have same output format) and put
> it into a CSV format to import into a database or spreadsheet.
> While we of course have Static / Connected routes, we also have lots
> of dynamic routing coming in via OSPF, BGP, RIP, etc...
>
> The output of the command is easy enough for me to get into text files
> via parimiko (on that, does this module or equivalent work on Python 3
> yet?) .. it's just tough to present the data into a csv or tabbed
> format.
>
> To me, although I've done similar things in the past, it's a fairly
> brutal output format to parse up.  I was about to post some sample
> input, but I am even having a hard time sanitizing the IP's for use on
> this forum (Any utility for that?) as it's filled with IP addresses
> that I cannot share.  I'd love some python module if anyone has an
> idea where I can get it?
>
> Perl does seem to have something similar :
>
> http://cpansearch.perl.org/src/MARKPF/Cisco-ShowIPRoute-Parser-1.02/Parser.pm
> however, I'd like to keep it in python...
>
> Mainly, did someone already do this so I don't have to reinvent this
> wheel (which probably won't roll straight)?
>
> Thanks in advance, and hopefully I've given enough information.. I've
> been trying to parse it for about 9 hours... but the script get's
> worse and worse as I keep finding flaws in my logic.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120304/3a9b5ae3/attachment.html>


More information about the Python-list mailing list