October 27th, 2004, 11:54 AM
C++ Telnet program
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.
October 27th, 2004, 01:10 PM
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/:
Last edited by dwise1_aol; October 27th, 2004 at 03:44 PM.
October 27th, 2004, 02:51 PM
If I were you I'd use the Expect language, it's great for scripting things like this.
October 27th, 2004, 02:54 PM
Use expect scripts. They are way simpler to write and maintain that a C++ code, for such tasks.
October 27th, 2004, 04:08 PM
Originally Posted by dwise1_aol
LOL was this here before, and I was just blind? My bad.
October 27th, 2004, 05:51 PM
Oh come on now! How could you possibly miss something that big?
Originally Posted by infamous41md
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.
October 27th, 2004, 06:41 PM
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