How to use "telnet" to launch another program on a remote machine from c++ code?

  • Follow


Hi,

The problem is:
1) The program will use telnet
2) It will connect to a host that the user will input to a
predetermined
    port
3) It will send predetermined commands to the running service.

The process I think should be

1)system("telnet remoteIP")
2)waitResponse
3)send("userId")
4)waitResponse
5)send("password")
6)waitResponse
7)send("myProgram")

My question are
1) How to wait for response, e.g. wait for "login" / "Password"
message.
2) How to send "userId", "password" and "myProgram"?
3) How to set a timeout if there is no response from remote machine?

Thanks!

0
Reply kimso.zhao (10) 12/2/2005 5:07:12 AM

kimso.zhao@gmail.com wrote:
> Hi,
>
> The problem is:
> 1) The program will use telnet
> 2) It will connect to a host that the user will input to a
> predetermined
>     port
> 3) It will send predetermined commands to the running service.
>
> The process I think should be
>
> 1)system("telnet remoteIP")
> 2)waitResponse
> 3)send("userId")
> 4)waitResponse
> 5)send("password")
> 6)waitResponse
> 7)send("myProgram")
>
> My question are
> 1) How to wait for response, e.g. wait for "login" / "Password"
> message.
> 2) How to send "userId", "password" and "myProgram"?
> 3) How to set a timeout if there is no response from remote machine?
>
> Thanks!



   This was done a long  time ago  .....

   Look  at the  source code  for the  UUCP   programs

   uucico   in combination with the /etc/uucp/Systems  file
   waits for   ogin:   and   sword:


//Lars

0
Reply tunla 12/2/2005 7:29:24 AM


In article <1133508564.925347.31840@z14g2000cwz.googlegroups.com>, tunla <lars.tunkrans@bredband.net> wrote:
>
>    This was done a long  time ago  .....
>
>    Look  at the  source code  for the  UUCP   programs
>
>    uucico   in combination with the /etc/uucp/Systems  file
>    waits for   ogin:   and   sword:

Or better yet, use the 'expect' utility which is a much more robust and
currently maintained solution that can do significant error checking.

-Dan
0
Reply Dan 12/2/2005 7:38:47 AM

Where can I find some good stuff about 'expect'?
Any good example you can give me?
Thanks!

0
Reply kimso 12/2/2005 5:48:00 PM

kimso.zhao@gmail.com wrote on 2005-12-02 18:48:
> Where can I find some good stuff about 'expect'?
> Any good example you can give me?
> Thanks!
> 

A google for "expect telnet" gives for example http://expect.nist.gov/

-- 
- Erlend Leganger
0
Reply Erlend 12/2/2005 8:09:00 PM

4 Replies
587 Views

(page loaded in 0.582 seconds)

Similiar Articles:













7/22/2012 3:38:44 PM


Reply: