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} ...

Get Tcl 8.5 Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.