ruby / net-telnet Goto Github PK
View Code? Open in Web Editor NEWProvides telnet client functionality.
License: Other
Provides telnet client functionality.
License: Other
When I send XML command in pop.cmd("xml") { |c| use c in second action }
This is not working. Request timeout always. Is there anyway we can fix this?
Hello, is it possible to do this?
The host I'm connecting to does not have a prompt but you can issue commands upon connection and get a response. Currently I'm trying this with the following:
telnet = Net::Telnet::new(
'Host' => HOST,
'Port' => PORT,
'Timeout' => false,
'Prompt' => /.*/
)
But it fails with A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. - connect(2) for HOST port PORT.
.
If I can connect I was thinking I could then use 'Match'
when calling cmd
to match the end of the command output instead of the prompt, but I can't connect.
I'd really appreciate any help you can offer.
While using the cmd function, I'm trying to send an empty string (''). In this case I receive "> > " without any newline characters.
Instead if I send any character (e.g. "a") I obtain something like "> a\n> "
Why in the first case the newline is removed or not present? any idea?
When I send a host.cmd('comand')
the server waits for a second command for confirmation, how can I do that?
if I send a second host.cmd('yes'), the problem: Net::ReadTimeout with "timed out while waiting for more data" because the host close connection.
The 0.2.0 release requires ruby >= 2.3.0 which some major operating systems such as CentOS 7 does not provide. CentOS is usually behind a bit on versions, is >= 2.3.0 really required or can it be lowered?
A lot of things will have to to pin 0.1.1 like I did right after this release.
2018-07-25 12:38:16.766181 | centos-7 | Gem::InstallError: net-telnet requires Ruby version >= 2.3.0.
2018-07-25 12:38:16.766309 | centos-7 | An error occurred while installing net-telnet (0.2.0), and Bundler cannot
2018-07-25 12:38:16.766345 | centos-7 | continue.
2018-07-25 12:38:16.766419 | centos-7 | Make sure that `gem install net-telnet -v '0.2.0' --source
2018-07-25 12:38:16.766483 | centos-7 | 'https://rubygems.org/'` succeeds before bundling.
2018-07-25 12:38:16.766506 | centos-7 |
2018-07-25 12:38:16.766538 | centos-7 | In Gemfile:
2018-07-25 12:38:16.766619 | centos-7 | puppet-openstack_spec_helper was resolved to 13.0.0, which depends on
2018-07-25 12:38:16.766723 | centos-7 | beaker-rspec was resolved to 5.6.0, which depends on
2018-07-25 12:38:16.766800 | centos-7 | serverspec was resolved to 2.41.3, which depends on
2018-07-25 12:38:16.766872 | centos-7 | specinfra was resolved to 2.75.0, which depends on
2018-07-25 12:38:16.766912 | centos-7 | net-telnet
Best regards
For legacy telnet servers such as rmenu (FreeDOS), client data is often lost when sent too quickly. This happens even though the connection is TCP. So, it would be nice if net-telnet offered a configuration option for the client object, to wait that many seconds between each byte sent to the telnet server. This significantly improves data integrity.
For example, telnet clients running commands on FreeDOS servers, should wait about 1-2 seconds between each (hot)key press. What do you think, could net-telnet get this kind of configuration parameter?
I deal with a server that never send any prompt. So the cmd can't find any match string. I tried a correction (given here). I suggest to have a cmd option and to be able to send either a Prompt or a Match or a String option to the wait for to avoid the raise of a "tile out while waiting for more data". Is my solution correct ? Could it be possible to include this kind of solution in a next version of this project ?
def cmd(options) # :yield: recvdata
match = @options["Prompt"]
time_out = @options["Timeout"]
fail_eof = @options["FailEOF"]
typeMatch = "Prompt"
if options.kind_of?(Hash)
cmd = options["Cmd"] if options.has_key?("String")
if options.has_key?("String")
match = options["String"]
typeMatch="String"
end
if options.has_key?("Match")
match = options["Match"]
typeMatch="Match"
end
time_out = options["Timeout"] if options.has_key?("Timeout")
fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
else
cmd = options
end
self.puts(cmd)
if block_given?
waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
else
waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof})
end
end
(Moving from Ruby core bug report I filed 3 years ago, recently rejected because net-telnet has been extracted here. Originally reported on ruby 2.0.0p247 (2013-06-27 revision 41674) [armv6l-linux-eabihf] as https://bugs.ruby-lang.org/issues/8668 )
waitfor('Waittime'=>0) says it will not wait once the expected prompt has matched, yet if the remote end continues to send data, it will in fact wait, possibly forever.
Line 555 of net/telnet.rb (from 2.0.0) is:
until(prompt === line and not IO::select([@sock], nil, nil, waittime))
Which means even though prompt has matched, it will still call IO::select, and if new data has arrived, it will make another pass through this loop. In my case there is constantly new data arriving (though it is only telnet control data) and so the loop never exits even though the prompt was matched long ago.
I fixed this with:
until(prompt === line and (waittime==0 or not IO::select([@sock], nil, nil, waittime)))
Though I don't know what other implications that change might have.
There is a related bug with 'Timeout': if the remote end keeps sending data (even if only telnet control codes), but it never matches the prompt, waitfor() will wait forever.
I have simple script to send emails using ruby telnet library
here is my code
require 'net/telnet'
localhost = Net::Telnet::new("Host" => "smtp.gmail.com","Timeout" => 10, "Port" => 587, "Waittime" => 20, "
FailEOF" => true )
localhost.cmd("mail from: [email protected]"){ |c| print c }
localhost.cmd("rcpt to: [email protected]"){ |c| print c }
localhost.close
I got this error 'waitfor' timed out while waiting for more data again and again
why I am getting this error again and again, what's wrong in the code snipet?
Hi.
I want to send window size of telnet option.
How can I send OPT_NAWS ?
Thank you for response.
Nest regards.
Is it possible to connect to a telnet server that has no username/password ? I couldn't find a way to do so - I've tried blank/blank, nil/nil or .login with no arguments but obviously it failed.
I am working with net-telnet to validate some email addresses from smtp server. I am facing Issues with receiving server responses.
This is what I am doing -
require 'net/telnet'
require 'socket'
me = Socket.gethostname
host = 'gmail-smtp-in.l.google.com'
port = 25
tn = Net::Telnet.new('Host' => host, 'Port' => port, "Telnetmode" => false, 'Prompt' => /^[0-9]{3}\s.*$/)
# this returns <Net::Telnet:0x007f8e8fa45ce8 @options={"Host"=>"gmail-smtp-in.l.google.com", "Port"=>25, "Telnetmode"=>false, "Prompt"=>/^[0-9]{3}\s.*$/, "Timeout"=>10, "Waittime"=>0, "Binmode"=>false}, @telnet_option={"SGA"=>false, "BINARY"=>false}, @sock=#<TCPSocket:fd 11>>
tn.cmd("HELO #{me}")
# this returns 220 mx.google.com ESMTP a187si79006pgc.762 - gsmtp\n
tn.cmd("MAIL FROM:<[email protected]>")
# this should return 250 2.1.0 OK j20si85062pfn.300 - gsmtp\n
# but what i am getting is 250 mx.google.com at your service
This seems to be the response from the previous command execution, that is being sent as soon as I execute the next command. i am not sure what is happening around. And this same pattern follows for the other consecutive commands. I keep receiving the responses from the previous command executions when I execute the next command.
I am using the Net::Telnet
gem to connect to remove servers, most of the times, the returned string by the cmd
method has UTF-8
encoding, but the other day, one of the outputs from the server returned the character "ñ"
and when the character is present in the output the encoding from the string is BINARY
, I could not figure out where this change in the encoding is happening and why
client = Net::Telnet.new('Host' => "192.168.1.2", 'Port' => 23, 'Prompt' => //, 'Waittime' => 0.5, 'Timeout' => 30)
result_1 = client.cmd("test 1") # command does not return ñ
result_1.encoding -> #<Encoding:UTF-8>
result_2 = client.cmd("test 2") # command does return ñ
result_2.encoding -> #<Encoding:BINARY>
ruby 3.2.0
net-telnet 0.2
I wonder to know why the prompt with string option is write with Regexp.quote(options["String"])
? It is impossible to give a regex to control the end of waitfor.
This might be correct if the "String" option was treated as a regular expression like this: Regexp.new( options["String"] )
. Just remove the Regexp.quote().
I am right ? Is there other solution to control the prompt with a regex ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.