Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to simulate telnet command using exec?

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I would like to run a telnet command to a certain IP
The problem is that after running it at Dos it requires UserID and Password. How do I simulate the entering of this information and how do I use the open session in order to transmit commands to the IP through the telnet session I've opened?
 
Let me clarify my problem:

set fid [socket <ip address> 23]

puts $fid <user id>
puts $fid <password
puts $fid {some command}
flush $fid

set theString [read $fid]
puts $theString

I would like to see the {some command} result but I can't see a thing...
 
If you are attempting to use the vanilla socket
api for telnet interaction and expect to be able
to view the results of commands executed via the
telnet protocol you should check out the telnet
rfc:
Automating interactive applications is easy with
the tcl extension expect, now available for both
windows and unix. Many expect scripts have been
written to interact with a telnet session. Do a
google search.
Heck here is a short one:
Code:
package require Expect
set prompt ".*@.*"
spawn -noecho telnet [lindex $argv 0] 

            expect {
                      -re ".*ogi" {
                           send_user "\nLogin name: "
                           set name [gets stdin]
                           send "$name\r"
                           expect -re ".*asswor.* {
                                   send_user "Pass: "
                                   set pass [gets stdin]
                                   send "$pass\r"
                                   expect -re $prompt {
                                   interact
                                   }
                           }
                       }
                    eof { send_user "Unexpected disconnect"}
                    timeout { send_user "Timed out..."}
        }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top