Automated telnet using C++

Decotey

Expert Member
Joined
Oct 14, 2004
Messages
1,063
Reaction score
2
Location
.
Hey

I been trying to write a C++ for restarting my router when the line drops, but I'm struggling to get my telnet commands to work. Telnet is installed and I can do a normal telnet from cmd, but when I run it from my c++ program it doesn't recognize telnet as a command.

I'm simply trying to do the following:
int main(void)
{
system("telnet");

}

'telnet' is not recognized as an internal or external command,
operable program or batch file.

this is what I'm getting out of cmd.

Ive also tried "start telnet" but that doesn't work either.

Strange thing is the exe works just fine on my laptop, so something is stopping telnet from running

Anyone got any advice?
 
Last edited:
it'll be quicker to write a shell script...otherwise check that telnet is in the path.
 
Try using the full path to telnet.
(which OS are you using?)

If your router supports ssh, it would be much easier to script, than telnet.
 
Are you using Windows 7? By default, Telnet is not installed.

"Turn Windows features on or off" in Control Panel -> Programs And Features.

EDIT: Ignore... I only see now that "Telnet is installed..."
 
Last edited:
It's probably not in the Environmental Variables so you can't refer to it unless you're using the full path so either go use the full path as Nod suggested or go change you Environmental Variables in Device Manager or through cmd with PATH=%PATH%;full path for telnet
 
Ive tried the full path, it just doesn't believe that telnet is installed if I run it from a script. If I telnet normally no problems 0.o

Ill look into ssh a bit later, might be a better option
 
Found a ssh library for C: http://www.libssh2.org/examples/ssh2_exec.html

The biggest reason to not use telnet, is that all your data passes, in clear text, over the network. It is the easiest way for anybody that runs wireshark or tcpdump on the network, to gather login/password combinations.

Always use ssh, or other encrypted methods of communicating with remote servers. Ideally the telnet server process should not even be running.
 
Last edited:
Look into this http://docs.activestate.com/activetcl/8.5/expect4win/ex_usage.html

ActiveState Expect for Windows provides the ability to automate interactive programs from within the Windows environment. For example, use Expect for Windows to telnet to a Unix client and run commands on the remote system. By driving the telnet session with Expect for Windows, you have the ability to fully automate the process.
 
Did this whole router interaction thing a while ago but can't for the life of me remember how. I don't think I used the windows exe though...was via code. All I remember is that it was mad time sensitive...i.e. code ended up being unreliable & full of sleep(100)'s. Ugh.

The biggest reason to not use telnet, is that all your data passes, in clear text, over the network. It is the easiest way for anybody that runs wireshark or tcpdump on the network, to gather login/password combinations.
Agreed on ssh...but I think telnet would (theoretically) be an acceptable risk here. The WAN should be wpa encrypted and if the attacker is capable of breaking wpa then a router login isn't gonna be much of a challenge.
 
Whenever I see the word "telnet" I cringe.
Executing remote commands via SSH is quite easy and a far more secure than telnet.
You can also easily set up key based authentication with SSH between your PC and the router to avoid the normal login prompts.

Alternatively if your router has a web interface you could do some Perl scripting to log in and reboot the router via the router's HTTP interface.
 
Top
Sign up to the MyBroadband newsletter
X