Module: Ronin::Network::Mixins::Telnet

Includes:
Mixin, Telnet
Defined in:
lib/ronin/network/mixins/telnet.rb

Overview

Adds Telnet convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - Telnet host.
  • port (Integer) - Telnet port.
  • telnet_user (String) - Telnet user to login as.
  • telnet_password (String) - Telnet password to login with.
  • telnet_proxy (String) - Telnet proxy.
  • telnet_ssl (Boolean) - Enable Telnet over SSL. Defaults to true.

Constant Summary

Constants included from Telnet

Telnet::DEFAULT_PORT, Telnet::DEFAULT_PROMPT, Telnet::DEFAULT_TIMEOUT

Instance Method Summary collapse

Methods included from Mixin

#host_port

Methods included from UI::Output::Helpers

format, #print_debug, #print_error, #print_exception, #print_info, #print_warning, #printf, #putc, #puts, #write

Methods included from Telnet

default_port, default_port=, default_prompt, default_prompt=, default_timeout, default_timeout=, proxy, proxy=

Instance Method Details

#telnet_connect(options = {}) {|connection| ... } ⇒ Net::Telnet (protected)

Creates a connection to a Telnet server. The host, port, telnet_user, telnet_password, telnet_proxy and telnet_ssl parameters will also be used to connect to the Telnet server.

Examples:

telnet_connect
# => Net::Telnet

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :port (Integer) — default: Network::Telnet.default_port

    The port to connect to.

  • :binmode (Boolean)

    Indicates that newline substitution shall not be performed.

  • :output_log (String)

    The name of the file to write connection status messages and all received traffic to.

  • :dump_log (String)

    Similar to the :output_log option, but connection output is also written in hexdump format.

  • :prompt (Regexp) — default: Network::Telnet.default_prompt

    A regular expression matching the host command-line prompt sequence, used to determine when a command has finished.

  • :telnet (Boolean) — default: true

    Indicates that the connection shall behave as a telnet connection.

  • :plain (Boolean)

    Indicates that the connection shall behave as a normal TCP connection.

  • :timeout (Integer) — default: Network::Telnet.default_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.

  • :wait_time (Integer)

    The amount of time to wait after seeing what looks like a prompt.

  • :proxy (Net::Telnet, IO) — default: Network::Telnet.proxy

    A proxy object to used instead of opening a direct connection to the host.

  • :user (String)

    The user to login as.

  • :password (String)

    The password to login with.

Yields:

  • (connection)

    If a block is given, it will be passed the newly created Telnet connection.

Yield Parameters:

  • connection (Net::Telnet)

    The newly created Telnet connection.

Returns:

  • (Net::Telnet)

    The Telnet session

See Also:


139
140
141
142
143
# File 'lib/ronin/network/mixins/telnet.rb', line 139

def telnet_connect(options={},&block)
  print_info "Connecting to #{host_port} ..."

  return super(self.host,telnet_merge_options(options),&block)
end

#telnet_session(options = {}) {|session| ... } ⇒ Object (protected)

Starts a session with a Telnet server. The host, port, telnet_user, telnet_password, telnet_proxy and telnet_ssl parameters will also be used to connect to the Telnet server.

Examples:

telnet_session do |movie|
  movie.each_line { |line| puts line }
end

Yields:

  • (session)

    If a block is given, it will be passed the newly created Telnet session. After the block has returned, the Telnet session will be closed.

Yield Parameters:

  • session (Net::Telnet)

    The newly created Telnet session.

See Also:


168
169
170
171
172
173
174
175
176
177
# File 'lib/ronin/network/mixins/telnet.rb', line 168

def telnet_session(options={},&block)
  super(telnet_merge_options(options)) do |sess|
    yield sess if block_given?

    print "Logging out ..."
  end

  print_info "Disconnected to #{host_port}"
  return nil
end