3

I'm able to access a telnet server via PuTTY which opens a terminal and allows me to send commands to retrieve data/logs and start/stop processes. I'd like to begin some research into how to access this server via C++ in order to automate the connection and the commands for testing. Basically I need a telnet client that can connect and authenticate itself, and write and read to/from the server as if I'm typing in a terminal. Where should I start my research? I've tried a couple examples including:

http://lists.boost.org/boost-users/att-40895/telnet.cpp

When I compile and run

./telnet 192.168.1.26 23

Nothing happens, but when I connect to the server with PuTTY I get:

QNX Neutrino (localhost) (ttyp0)

login: root  
password:  
#  

Any help would be greatly appreciated.
Notes:
- I am using a Mac running OS X Version 10.7.3 with i686-apple-darwin11-llvm-gcc-4.2
- I am allowed to be doing this.
- I use PuTTY on my Windows 7 machine, the connection is ethernet to USB ethernet adapter, and the settings for the Local Area Connection Properties > TCP/IPv4 Properties: are a specific IP address, Subnet Mask, and Default gateway, which might be useful information.

Thanks

JuJoDi
  • 14,627
  • 23
  • 80
  • 126
  • 2
    What about starting with putty? Its source is available... – Mat May 07 '12 at 19:20
  • *"the connection is ethernet to USB ethernet adapter, and the settings for the Local Area Connection Properties > TCP/IPv4 Properties: are a specific IP address, Subnet Mask, and Default gateway, which might be useful information"* Your OS should (in fact *does*) shield the application from all of this junk. – dmckee --- ex-moderator kitten May 07 '12 at 19:23
  • Why: you can use ssh to authenticate and run commands: ssh – Martin York May 07 '12 at 19:27

2 Answers2

6
  1. Learn how to program TCP/IP sockets. You can use the boost libraries, or straight C style BSD sockets. Some info here, here and here. If paper is your thing, you could get Volume 1 of Unix Network Programming. That book has such a good reputation that you get votes just for mentioning it on StackOverflow.

  2. What you want to do closely matches the functionality of telnet and expect. You can have a look at there sources here and here for ideas.

  3. Consider just using expect to solve your problem :)

Michael Slade
  • 13,802
  • 2
  • 39
  • 44
1

You should start by learning the network API for the system you're trying to connect from. Telnet is just sending straight up text through a tcp/ip socket.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125