If you just really want the index of interfaces,
$s walk x ifIndex {puts $x} will give it to you
Instead of just getting the list of interfaces, it might be useful to
get the list of up interfaces.
$s walk x ifAdminStatus {command}
or
$s walk x ifOperStatus {command}
The difference between AdminStatus and OperStatus is that AdminStatus
is a person turing the port off, and OperStatus is the equivalent of
no carrier, or link-down.
routing table is in ipRouteTable
Dumping it will give you probably more information than you want,
so maybe you just want ipRouteDest which returns an IP address.
ipRouteMetric1 might be useful too if you use different route types
like RIP, OSPF, EGP, IGRP, etc..
I'm including a simple program that I wrote that does an SNMP equivalent
of a traceroute. It draws little circles representing the hops, and tries
to get SNMP information from each node. Many nodes out there won't
respond to SNMP (for administrative reasons), so it will do an ICMP
nexthop calculation in that case.
Anyway, it does pretty much what you want.
calculate next hop
calculate pipe bandwidth
calculate interface description
#!/opt/tcl7.5/bin/wish
load /opt/tcl7.5/lib/tnm2.1.4.so tnm
proc dodialog {widget title msg} {
if {[winfo exists $widget]} {return}
toplevel $widget -class Dialog
wm title $widget "$title"
message $widget.m -text "$msg" -width 300 -font helvetica-bold-14
button $widget.b -text OK -command "destroy $widget"
pack $widget.m -side top -expand true -fill both
pack $widget.b -side top -expand false -fill y
}
lappend auto_path /home/ens/doug/tcl $tk_library/demos
if {[llength $argv] < 1} {
puts "Usage: snmptrace dest_host"
exit
}
set d_host [lindex $argv 0]
#puts "Starting at $s_host to $d_host"
if {![string match {[0-9.]*} $d_host]} {
set d_final [nslook $d_host]
} else {
set d_final $d_host
}
#canvas .c -relief flat -width 800 -height 225
#pack .c
set x 50
set y 75
set s [snmp session]
set s2 [snmp session]
set hop 1
set node1 ""
set t [lindex [icmp trace $hop $d_host] 0]
puts "$t $d_final"
while {[string compare [lindex $t 0] $d_final] != 0} {
if {$x > 500} {
set x 50
set y [expr $y + 75]
}
set newnode [mkNode $x $y node$hop]
update idletasks
set node2 $node1
set node1 [.c find withtag node$hop]
set new [.c create text $x $y -tags node$hop -text "$hop"]
set nodeX($new) $x
set nodeY($new) $y
set edgeFirst($new) {}
set edgeSecond($new) {}
if {$node2 != ""} {
set edge [mkEdge $node1 $node2]
update idletasks
}
set x [expr $x + 50]
set y [expr $y + 5]
$s configure -address [lindex $t 0]
# track down next route with ICMP timeout
catch {set oldaddr $haddr} e
set t [lindex [icmp trace $hop $d_host] 0]
set haddr [lindex $t 0]
set i_p [split $haddr {.}]
set dnet ""
# Find destination net
append dnet [lindex $i_p 0] "." [lindex $i_p 1] "." [lindex $i_p 2] ".0"
puts "haddr $haddr $dnet"
# Get output interface for previous router
if {![regexp read $e]} {
$s2 configure -address $oldaddr
if {![catch {set outport [$s2 get ipRouteIfIndex.$dnet]}]} {
set pout [lindex [lindex $outport 0] 2]
append msg($oldaddr) " leaving port $pout"
puts "pout $pout"
}
}
# Try to resolve name
if [catch {set hname [nslook $haddr]} err] {
set hname $haddr
}
# Get SNMP information
if [catch {set port [lindex [$s get ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex.$dnet] 0]} err] {
set msg($haddr) "hop $hop to $hname - no SNMP info"
} else {
set port [lindex $port 2]
set descr [lindex [$s get interfaces.ifTable.ifEntry.ifDescr.$port] 0]
set descr [lindex $descr 2]
set speed [lindex [$s get interfaces.ifTable.ifEntry.ifSpeed.$port] 0]
set speed [expr [lindex $speed 2] / 1000 ]
set msg($haddr) "hop $hop to $hname port$port ($descr) at $speed Kbits/s"
if {$node2 != ""} {
case $speed in {
100000 ".c itemconfigure $edge -fill red -width 5"
10000 ".c itemconfigure $edge -width 5"
1544 ".c itemconfigure $edge -fill red"
768 ".c itemconfigure $edge -fill blue"
56 ".c itemconfigure $edge -fill green"
* ".c itemconfigure $edge -fill gray"
}
}
}
puts $msg($haddr)
.c bind node$hop <Button-3> "dodialog .m$hop \"Node $hop info\" {$msg($haddr)} "
set hop [expr $hop + 1]
}
puts done
bind .c <Key-q> exit
bind . <Key-q> exit
-- ____________________________________________________________________________ Doug Hughes Engineering Network Services System/Net Admin Auburn University doug@eng.auburn.edu
-- !! This message is brought to you via the `tkined & scotty' mailing list. !! Please do not reply to this message to unsubscribe. To subscribe or !! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>. !! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.