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.
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}