File: list-routes.py

package info (click to toggle)
snimpy 0.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 484 kB
  • ctags: 435
  • sloc: python: 3,361; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/snimpy

from __future__ import print_function

from socket import inet_ntoa

load("IP-FORWARD-MIB")
m=M()

print("Using IP-FORWARD-MIB::ipCidrRouteTable...")
routes = m.ipCidrRouteNextHop
for x in routes:
    net, netmask, tos, src = x
    print("%15s/%-15s via %-15s src %-15s" % (net, netmask, routes[x], src))

print

print("Using IP-FORWARD-MIB::inetCidrRouteTable...")
routes = m.inetCidrRouteIfIndex
for x in routes:
    dsttype, dst, prefix, oid, nhtype, nh = x
    if dsttype != "ipv4" or nhtype != "ipv4":
        print("Non-IPv4 route")
        continue
    print("%15s/%-2d via %-15s" % (inet_ntoa(dst), prefix, inet_ntoa(nh)))