views:

207

answers:

1

Background

Part of my work in networking and telco involves automating telnet sessions when legacy hardware doesn't offer easy solutions in other interfaces. Many older pieces of equipment can only be accessed via craft ports (RS-232 serial ports), SNMP, or telnet. Sometimes telnet is the only way to access specific information, however telnet is designed as a human interface and thus requires screen scraping. In addition, there is also the issue of scraping screens where only portions are updated in order to save bandwidth (see ncurses). In my work I have used ActiveState Expect and the Python telnet library.

Question

Which languages and libraries are able to automate telnet sessions and have the following requirements:

  • Suitable for large projects (e.g. Tcl doesn't seem to scale as well as Python in my experience and seems outdated)
  • Cross Platform (e.g. Pexpect does not work on Windows and Activestate Expect behaves differently on Windows plus requires DEP on newer machines to be turned off)
  • Able to screen scrape sessions that repaint portions of the screen (similar to the behavior of ncurses in command-line programs)
  • Free as in beer!

A preferable solution would also include the following:

  • Easily redistributable (e.g. Does not require some huge runtime to be installed on a machine.)
  • Also works for SSH, serial connections, and other command-line interfaces.
+1  A: 

Take a look at demos/Expect/term_expect in the ActiveTcl distribution. It emulates a cursor-addressable terminal and allows you to test output at specific screen locations. Check out the example screen-scraping code at the end of the file.

Colin Macleod
That's interesting, but what if a user does not know where output will be located? Also, doesn't the location vary based on the current screen size, or is there a default screen size that most terminals agree on?
pokstad
Back when terminals were hardware, most had 80 columns x 24 rows, so I would expect that to be the default size, and that's the size term_expect uses. You could experiment to find the screen locations of fields you want, or you could grab the whole screen area with [$term get 1.0 end] and then use regexp or other string commands to search within that.
Colin Macleod