I got this big problem. I have to automate a Telnet connection for this project but I have no idea on how to do that in C/C++ :( . I need to be able to send an ascii file's contents (1 command per line) so that it will automate those commands. Then I need to save the output in a text file, and have the program analyze it. Finally i have to repeat the process automatically for the next ip in line.

If this can be done all automatically already with an exsisting program, could you please direct me to it?

Any help is greatly appreciated!

Recommended Answers

All 2 Replies

Open winsock on port 23, then just send the data away. Assuming you'll get a reply for every telnet command you send, you can just use blocking winsock commands in a loop.

readdata(Filename, CommandArray)
 for (int x=0;x<UpperBound(IPList);x++)
 	for (int i=0;i<UpperBound(CommandArray);i++)

you need to make sure u terminate everything u send with "\r\n", or telnet server wont recognize it. and u'll need to login properly, i'd check out part of the telnet RFC, or try and google for a quick telnet tutorial; as well as sniffing your own traffic on a few sessions - that is one of best ways to write a quick prog that actually works. another option, would be to use the Expect scripting language, quite handy for things liek this: http://expect.nist.gov/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.