tags:

views:

962

answers:

4

Is there a telnet library that I can use with c++ (for Linux)? I would like to telnet to a remote device, run some commands, parse the o/p and present the results.

+4  A: 

Telnet is just sending ascii text one byte at a time over a socket so this wouldn't be hard to implement. Just open the socket to the correct port and then read/write data to it and display it to the screen.

Jeff Tucker
The reason I prefer a library is exactly the steps to avoid as outline. It's very easy to do this in Java (Apache lib). Can this be done in c++ or is it a PITA?
I'm more familiar with Winsock than berkely sockets but it's not that hard to do. Socket code looks intimidating at first but it's not that hard and you don't need to do anything special to connect for this thing in terms of socket options or protocol wierdness or funky errors or anything like that. This page looks like it has everything you would need to write the code for this: http://www.tenouk.com/Module40.html
Jeff Tucker
Socket program is simple in theory - it's all the details of error handling and things that can go wrong when you don't have control of the other machine that are tricky
Martin Beckett
Things likely to go wrong that you have to handle:1. connection times out2. connection is forcibly closed by remote host (a FIN or RST packet)3. remote host cannot be found (DNS failure or destination unreachable)4. remote host refused connection (remote host not listening on that port or refusing to respond by sending a RST or FIN)There are other things but as long as you handle those gracefully you should be ok for a simple telnet client. If you're handling thousands of simultaneous connections it gets much harder.
Jeff Tucker
+4  A: 

Here is a simple example Telnet client written using the Boost asio library.

Brandon E Taylor
This is what I was looking for
+3  A: 

There is an example of using boost::asio to write a telnet client in this thread

Martin Beckett
+1  A: 

I see Winsock as perfectly adequate for this. There's very little to implementing it. 'Telnet' is just a socket connection. There's no abstraction layer to contemplate over opening a socket, sending stuff down it and getting the response.

Rushyo