[Tutor] How to get ipRouteTable from Cisco router?

Костиков Сергей Николаевич SERKOS at avalon.ru
Thu Apr 29 20:30:25 CEST 2010


Hello!

I want to get route tables from Cisco routers in the network. What i
have:
<snip>
   else:
       for varBindTableRow in varBindTable:
           for oid, val in varBindTableRow:
                print varBindTableRow
 <snip>

Result:

Code: Select all
[(ObjectName('1.3.6.1.2.1.4.21.1.1.0.0.0.0'), IpAddress('0.0.0.0'))]
[(ObjectName('1.3.6.1.2.1.4.21.1.1.10.9.0.0'), IpAddress('10.9.0.0'))]
[(ObjectName('1.3.6.1.2.1.4.21.1.1.192.168.1.0'),
IpAddress('192.168.1.0'))]

How can i get IpAddress values from this list and put they in the
dictionary? Or may be there is much better solution?

My guess, from looking at what you have there, str(varBindTableRow[1]) should get your IP address in a string format. In any case the varBindTableRow[1] will contain the IpAddress object(?) that is displayed in the lists.

HTH,
Wayne


Results are: 

1. print str(varBindTableRow[1])

IndexError: list index out of range

2. print str(varBindTableRow[0][1])

АЁ

3. but for ipRouteIfIndex, i have

print str(varBindTableRow[0][1])

0
0
1

So, it works for IfIndex, RouteType, but not for Dest, Mask and NextHop as they return ip.

Thanks indeed.



More information about the Tutor mailing list