472,791 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Sending commands to Telnet from C++

I am trying to reboot several devices on my private network through telnet. I wrote a vbs that does the operation but i cannot select any other window while it is running of the input will not go into the telnet window created. I have begun to convert the code to C++ and am having problems I can get telnet to open to the ip address that I want but do not know how to pass any commands to it. I have read about 30 different website and people say how you do it but noone has provided any sample code of how it would work. Here is the code that I have so far.

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <comdef.h>
  5. #include <atlbase.h>
  6.  
  7. using namespace std;
  8. string ipaddress;
  9. string rebootradio (string);
  10.  
  11. int main()
  12. {
  13.     string telnetid, telnetpw;
  14.  
  15.     telnetid = "xxxx";
  16.     telnetpw = "xxxx";
  17.  
  18.  
  19.     rebootradio ("192.168.1.2");
  20.     rebootradio ("192.168.1.3")
  21.     rebootradio ("192.168.1.4")
  22.     rebootradio ("192.168.1.5")
  23.     rebootradio ("192.168.1.6")
  24.     rebootradio ("192.168.1.9")
  25.     rebootradio ("192.168.1.11")
  26.     rebootradio ("192.168.1.12")
  27.     rebootradio ("192.168.1.13")
  28.     rebootradio ("192.168.1.14")
  29.     rebootradio ("192.168.1.15")
  30.     rebootradio ("192.168.1.16")
  31.     rebootradio ("192.168.1.17")
  32.     rebootradio ("192.168.1.18")
  33.     rebootradio ("192.168.1.19")
  34.     rebootradio ("192.168.1.20")
  35.     rebootradio ("192.168.1.21")
  36.     rebootradio ("192.168.1.22")
  37.     rebootradio ("192.168.1.30")
  38.     rebootradio ("192.168.1.31")
  39.     rebootradio ("192.168.1.32")
  40.     rebootradio ("192.168.1.33")
  41.     rebootradio ("192.168.1.34")
  42.     rebootradio ("192.168.1.35")
  43.     rebootradio ("192.168.1.36")
  44.     rebootradio ("192.168.1.37")
  45.     system ("Pause");
  46.     return 0;
  47. }
  48.  
  49.  
  50. string rebootradio (string ipaddress)
  51. {
  52.          system (("Telnet " + ipaddress).c_str()); 
  53.           ("lego");
  54.          system ("mania");
  55.          wshShell.SendKeys "iden radio 1 reset on{ENTER}" 'repeat as needed 
  56.          wscript.Sleep 2000 
  57.          wshShell.SendKeys "iden radio 2 reset on{ENTER}" 'repeat as needed 
  58.          wscript.Sleep 2000 
  59.          wshShell.SendKeys "exit{ENTER}" 'close telnet session' 
  60.          wscript.Sleep 2000 
  61.          wshShell.SendKeys "{ENTER}" 'get command prompt back 
  62.          wscript.Sleep 2000 
  63.          wshShell.SendKeys "exit{ENTER}" 'close cmd.exe
  64. }
  65.  
as i said i have started to convert it but have not finished it gets to the login name part of the telnet session and I do not know how to take my information from the program.
Jan 27 '09 #1
0 4746

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Abel | last post by:
I have written a script that makes a telnet connection, runs various commands, and returns the output. That was the easy bit :) However, to close the session, I need to send ^] followed by quit. ...
4
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to...
2
by: Zach Flynn | last post by:
Ok, so I'm programming in Unix if that makes any difference. And I'm doing: system("telnet somehost.com 25"); But I can't figure out how to send a command to it. Like, for example, I would...
7
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a...
2
by: barry | last post by:
The code below is in a button but though there is no error message of any kind I am not getting the email which I am sending to myself. Any help would be appreciated. ...
0
by: knowthediff | last post by:
Hello, I have a VS 2005 windows form app that I am creating. It uses Async socket to telnet which sends and receives commands. Everything seems to be working fine until I attempt to process a...
3
by: surajsingh | last post by:
Hi, I have a perl script which uses Net::Telnet module to open a telnet session with my unix boxes, and executes lot of commands on those boxes. As this module is implemented, when 'cmd' is...
5
by: pbd22 | last post by:
Hi. Anybody know of any good code examples out there on how to take a telnet command and parse it? Thanks!
2
by: HTCGuy | last post by:
Hi, im building an application that has to run a series of simple telnet commands . login wget some links chmod some files exit The only thing Ive found sofar are massive fully function c#...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.