module Ronin::Support::Network::Telnet::Mixin
Provides helper methods for using the Telnet
protocol.
Public Instance Methods
telnet_connect(host, proxy: Telnet.proxy, port: Telnet::DEFAULT_PORT, binmode: false, wait_time: 0, prompt: Telnet::DEFAULT_PROMPT, timeout: Telnet.default_timeout, telnet: nil, plain: nil, user: nil, password: nil, output_log: nil, dump_log: nil) { |telnet| ... }
click to toggle source
Creates a new Telnet
connection.
@param [String] host
The host to connect to.
@param [Integer] port
The port to connect to.
@param [Boolean] binmode
Indicates that newline substitution shall not be performed.
@param [String, nil] output_log
The name of the file to write connection status messages and all received traffic to.
@param [String, nil] dump_log
Similar to the `:output_log` option, but connection output is also written in hexdump format.
@param [Regexp] prompt
A regular expression matching the host command-line prompt sequence, used to determine when a command has finished.
@param [Boolean] telnet
Indicates that the connection shall behave as a telnet connection.
@param [Boolean] plain
Indicates that the connection shall behave as a normal TCP connection.
@param [Integer] timeout
The number of seconds to wait before timing out both the initial attempt to connect to host, and all attempts to read data from the host.
@param [Integer] wait_time
The amount of time to wait after seeing what looks like a prompt.
@param [Net::Telnet, IO
, nil] proxy
A proxy object to used instead of opening a direct connection to the host.
@param [String, nil] user
The user to login as.
@param [String, nil] password
The password to login with.
@yield [telnet]
If a block is given, it will be passed the newly created Telnet session.
@yieldparam [Net::Telnet] telnet
The newly created Telnet session.
@return [Net::Telnet]
The Telnet session
@example
telnet_connect('towel.blinkenlights.nl') # => #<Net::Telnet: ...>
@example
telnet_connect('towel.blinkenlights.nl') do |movie| movie.each_line { |line| puts line } end
@api public
# File lib/ronin/support/network/telnet/mixin.rb, line 105 def telnet_connect(host, # connection options proxy: Telnet.proxy, port: Telnet::DEFAULT_PORT, binmode: false, wait_time: 0, prompt: Telnet::DEFAULT_PROMPT, timeout: Telnet.default_timeout, telnet: nil, plain: nil, # authentication options user: nil, password: nil, # log options output_log: nil, dump_log: nil) host = DNS::IDN.to_ascii(host) telnet_options = { 'Host' => host, 'Port' => port, 'Binmode' => binmode, 'Waittime' => wait_time, 'Prompt' => prompt, 'Timeout' => timeout } telnet_options['Telnetmode'] = true if (telnet && !plain) telnet_options['Output_log'] = output_log if output_log telnet_options['Dump_log'] = dump_log if dump_log telnet_options['Proxy'] = proxy if proxy telnet = Net::Telnet.new(telnet_options) telnet.login(user,password) if user if block_given? yield telnet telnet.close else return telnet end end