O'Reilly logo

Tcl 8.5 Network Programming by Piotr Beltowski, Wojciech Kocjan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Tcl for SNMP communication

Now that we have performed SNMP queries using TkIned, we can move on to using Scotty from Tcl directly to communicate over SNMP.

Querying SNMP in Tcl

The Tnm package offers a large number of features. Main part of its functionality is related to SNMP and MIB.

A quick example to query SNMPv2-MIB::sysContact value over SNMP can be as follows:

set session [Tnm::snmp generator]
$session configure -address "192.168.2.2" \
-version "SNMPv1" -community "private"
puts [$session get SNMPv2-MIB::sysContact.0]

This will create a connection handle, configure it to query the IP 192.168.2.2 over SNMPv1 protocol and get sysContact value. This will print out something like the following:

{1.3.6.1.2.1.1.4.0 {OCTET STRING} root@router} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required