#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    16
    Rep Power
    0

    C++ Telnet program


    Hi,
    I have a network power switch which is simply 8 power plugs. It has an IP address and can be asccessed via telnet. This allows someone to switch on an off power to equipment remotely by issuing commands via a telnet session
    My question is simple. I need to write a small C++ program which will open a telnet session and turn on an off switches at various times.
    My C++ is only fair and I've never done this kind of stuff before. Can someone point me in the right direction.
    Thanks Willl
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    How's your sockets programming? Or your C (it can just as easily be done in C -- you only stated that you are not that good in C++)? And what OS are you doing this on (that can make a big difference)?

    To write your own telnet client, you would need to know both sockets programming and the relevant RFCs. Of course, you could also Google for sample code that you might be able to rewrite into your application (but remember to call it "research"). Be sure to factor the learning curve into your time estimates.

    Our Linux instructor demonstrated using a shell script to automate the fetching of a stock quote from a web page (http) but using the built-in telnet utility.

    Furthermore, if you are running tcl, then you could use expect to script the telnet session that you need. I haven't ever used expect myself, but I understand that it was created just for this kind of situation (ie, automating interactive sessions).
    Book resource: O'Reilly's Exploring Expect at http://www.oreilly.com/catalog/expect/:
    Exploring Expect

    Full Description

    Expect is quickly becoming a part of every UNIX user's toolbox. It allows you to automate Telnet, FTP, passwd, rlogin, and hundreds of other applications that normally require human interaction. Using Expect to automate these applications will allow you to speed up tasks and, in many cases, solve new problems that you never would have even considered before.

    For example, you can use Expect to test interactive programs with no changes to their interfaces. Or wrap interactive programs with Motif-like front-ends to control applications by buttons, scrollbars, and other graphic elements with no recompilation of the original programs. You don't even need the source code! Expect works with remote applications, too. Use it to tie together Internet applications including Telnet, Archie, FTP, Gopher, and Mosaic.

    Don Libes is the creator of Expect as well as the author of this book. In Exploring Expect, he provides a comprehensive tutorial on all of Expect's features, allowing you to put it immediately to work on your problems. In a down-to-earth and humorous style, he provides numerous examples of challenging real-world applications and how they can be automated using Expect to save you time and money.

    Expect is the first of a new breed of programs based on Tcl, the Tool Command Language that is rocking the computer science community. This book provides an introduction to Tcl and describes how Expect applies Tcl's power to the new field of interaction automation. Whether your interest is in Expect or interaction automation or you simply want to learn about Tcl and see how it has been used in real software, you will find Exploring Expect a treasure trove of easy-to-understand and valuable information.
    Last edited by dwise1_aol; October 27th, 2004 at 02:44 PM.
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    If I were you I'd use the Expect language, it's great for scripting things like this.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    CA,USA
    Posts
    181
    Rep Power
    10
    Use expect scripts. They are way simpler to write and maintain that a C++ code, for such tasks.
  8. #5
  9. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Originally Posted by dwise1_aol
    Furthermore, if you are running tcl, then you could use expect to script the telnet session that you need. I haven't ever used expect myself, but I understand that it was created just for this kind of situation (ie, automating interactive sessions).
    Book resource: O'Reilly's Exploring Expect at http://www.oreilly.com/catalog/expect/:

    LOL was this here before, and I was just blind? My bad.
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Originally Posted by infamous41md
    LOL was this here before, and I was just blind? My bad.
    Oh come on now! How could you possibly miss something that big?

    I did come back later and edit in the reference to and quote from O'Reilly so that he would have a better idea of what Expect is, so then, no, it wasn't there before. Pointing him directly to the Expect site was a very good move on your part; I had forgotten the URL myself.
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Heh, trust me, I've been known to do dumber things than miss that, especially when I first wake up. :D

    ps. yes, i'm insane, I woke up at 2:30pm today, but I didn't go to bed till 8 :D

IMN logo majestic logo threadwatch logo seochat tools logo