How to telnet to a host?

Z

Zhao Yi

I use this code to telnet to a Windows Xp machine.

tn=Net::Telnet.new("Host" => "localhost","Timeout" => 10,"Prompt" =>
/[$%#>] \z/n)
tn.login("user", "123456"){|c| print c}

The output will be:

"
Welcome to Microsoft Telnet Service


login: zhaoyi

password:
"
and then timeout.
 
Z

Zhao Yi

I know what wrong with these code. It is because the password prompt is
different with the default one. It works when I set the PasswordPrompt
value. But after login, when I run a command I will get time out error.
Please see my code:

tn=Net::Telnet.new("Host" => "localhost","Timeout" => 10,"Prompt" =>
/[$%#>] \z/n){|c| print c}
tn.login({"Name"=>"user","Password" =>
"123456","LoginPrompt"=>/[Ll]ogin[: ]*\z/n,"PasswordPrompt"=>/password[:
]*\z/n}){|c| print c}

tn.cmd("dir"){|c| print c}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top