Module: Ronin::Support::Network::Telnet::Mixin

Defined in:
lib/ronin/support/network/telnet/mixin.rb

Overview

Provides helper methods for using the Telnet protocol.

Instance Method Summary collapse

Instance Method Details

#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| ... } ⇒ Net::Telnet

Creates a new Telnet connection.

Examples:

telnet_connect('towel.blinkenlights.nl')
# => #<Net::Telnet: ...>
telnet_connect('towel.blinkenlights.nl') do |movie|
  movie.each_line { |line| puts line }
end

Yields:

  • (telnet)

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

Yield Parameters:

  • telnet (Net::Telnet)

    The newly created Telnet session.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# 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.(user,password) if user

  if block_given?
    yield telnet
    telnet.close
  else
    return telnet
  end
end