By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,956 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,956 IT Pros & Developers. It's quick & easy.

Sending commands to Telnet from C++

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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