lib/ronin/network/telnet.rb in ronin-support-0.4.1 vs lib/ronin/network/telnet.rb in ronin-support-0.5.0.rc1
- old
+ new
@@ -38,11 +38,11 @@
# @return [Integer]
# The default Ronin Telnet port.
#
# @api public
#
- def Telnet.default_port
+ def self.default_port
@default_port ||= DEFAULT_PORT
end
#
# Sets the default Ronin Telnet port.
@@ -50,21 +50,21 @@
# @param [Integer] port
# The new default Ronin Telnet port.
#
# @api public
#
- def Telnet.default_port=(port)
+ def self.default_port=(port)
@default_port = port
end
#
# @return [Regexp]
# The default Ronin Telnet prompt pattern.
#
# @api public
#
- def Telnet.default_prompt
+ def self.default_prompt
@default_prompt ||= DEFAULT_PROMPT
end
#
# Sets the default Ronin Telnet prompt pattern.
@@ -72,21 +72,21 @@
# @param [Regexp] prompt
# The new default Ronin Telnet prompt pattern.
#
# @api public
#
- def Telnet.default_prompt=(prompt)
+ def self.default_prompt=(prompt)
@default_prompt = prompt
end
#
# @return [Integer]
# The default Ronin Telnet timeout.
#
# @api public
#
- def Telnet.default_timeout
+ def self.default_timeout
@default_timeout ||= DEFAULT_TIMEOUT
end
#
# Sets the default Ronin Telnet timeout.
@@ -94,21 +94,21 @@
# @param [Integer] timeout
# The new default Ronin Telnet timeout.
#
# @api public
#
- def Telnet.default_timeout=(timeout)
+ def self.default_timeout=(timeout)
@default_timeout = timeout
end
#
# @return [Telnet, IO, nil]
# The Ronin Telnet proxy.
#
# @api public
#
- def Telnet.proxy
+ def self.proxy
@proxy ||= nil
end
#
# Sets the Ronin Telnet proxy.
@@ -116,11 +116,11 @@
# @param [Telnet, IO, nil] new_proxy
# The new Ronin Telnet proxy.
#
# @api public
#
- def Telnet.proxy=(new_proxy)
+ def self.proxy=(new_proxy)
@proxy = new_proxy
end
#
# Creates a new Telnet connection.
@@ -189,32 +189,36 @@
# # => #<Net::Telnet: ...>
#
# @api public
#
def telnet_connect(host,options={})
- host = host.to_s
- telnet_options = {}
+ telnet_options = {
+ 'Host' => host.to_s,
+ 'Port' => (options[:port] || Telnet.default_port),
+ 'Binmode' => (options[:binmode] || false),
+ 'Waittime' => (options[:wait_time] || 0),
+ 'Prompt' => (options[:prompt] || Telnet.default_prompt),
+ 'Timeout' => (options[:timeout] || Telnet.default_timeout)
+ }
- telnet_options['Host'] = host
- telnet_options['Port'] = (options[:port] || Telnet.default_port)
- telnet_options['Binmode'] = options[:binmode]
- telnet_options['Output_log'] = options[:output_log]
- telnet_options['Dump_log'] = options[:dump_log]
- telnet_options['Prompt'] = (options[:prompt] || Telnet.default_prompt)
-
if (options[:telnet] && !options[:plain])
telnet_options['Telnetmode'] = true
end
- telnet_options['Timeout'] = (options[:timeout] || Telnet.default_timeout)
- telnet_options['Waittime'] = options[:wait_time]
- telnet_options['Proxy'] = (options[:proxy] || Telnet.proxy)
+ if options[:output_log]
+ telnet_options['Output_log'] = options[:output_log]
+ end
- user = options[:user]
- passwd = options[:passwd]
+ if options[:dump_log]
+ telnet_options['Dump_log'] = options[:dump_log]
+ end
+ if (proxy = (options[:proxy] || Telnet.proxy))
+ telnet_options['Proxy'] = proxy
+ end
+
session = Net::Telnet.new(telnet_options)
- session.login(user,passwd) if user
+ session.login(options[:user],options[:password]) if options[:user]
yield session if block_given?
return session
end