ronin-support 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/ChangeLog.md +42 -1
- data/README.md +4 -1
- data/gemspec.yml +2 -1
- data/lib/ronin/extensions.rb +2 -0
- data/lib/ronin/extensions/enumerable.rb +54 -0
- data/lib/ronin/extensions/file.rb +70 -2
- data/lib/ronin/extensions/ip_addr.rb +45 -45
- data/lib/ronin/extensions/regexp.rb +45 -0
- data/lib/ronin/extensions/resolv.rb +80 -0
- data/lib/ronin/extensions/string.rb +35 -32
- data/lib/ronin/formatting/extensions/binary/integer.rb +12 -5
- data/lib/ronin/formatting/extensions/binary/string.rb +44 -16
- data/lib/ronin/formatting/extensions/html/integer.rb +51 -31
- data/lib/ronin/formatting/extensions/html/string.rb +50 -31
- data/lib/ronin/formatting/extensions/http/integer.rb +10 -2
- data/lib/ronin/formatting/extensions/sql.rb +20 -0
- data/lib/ronin/formatting/extensions/sql/string.rb +98 -0
- data/lib/ronin/formatting/extensions/text/array.rb +11 -9
- data/lib/ronin/formatting/extensions/text/string.rb +213 -29
- data/lib/ronin/formatting/sql.rb +20 -0
- data/lib/ronin/network/extensions/http.rb +1 -0
- data/lib/ronin/network/extensions/http/net.rb +2 -2
- data/lib/ronin/network/extensions/http/uri/http.rb +226 -0
- data/lib/ronin/network/extensions/imap/net.rb +1 -1
- data/lib/ronin/network/extensions/ssl/net.rb +7 -1
- data/lib/ronin/network/http/proxy.rb +20 -21
- data/lib/ronin/network/mixins.rb +27 -0
- data/lib/ronin/network/mixins/esmtp.rb +165 -0
- data/lib/ronin/network/mixins/http.rb +723 -0
- data/lib/ronin/network/mixins/imap.rb +151 -0
- data/lib/ronin/network/mixins/pop3.rb +141 -0
- data/lib/ronin/network/mixins/smtp.rb +159 -0
- data/lib/ronin/network/mixins/tcp.rb +331 -0
- data/lib/ronin/network/mixins/telnet.rb +199 -0
- data/lib/ronin/network/mixins/udp.rb +227 -0
- data/lib/ronin/network/ssl.rb +17 -11
- data/lib/ronin/path.rb +3 -3
- data/lib/ronin/spec/ui/output.rb +28 -0
- data/lib/ronin/support.rb +3 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output.rb +21 -0
- data/lib/ronin/ui/output/helpers.rb +248 -0
- data/lib/ronin/ui/output/output.rb +146 -0
- data/lib/ronin/ui/output/terminal.rb +21 -0
- data/lib/ronin/ui/output/terminal/color.rb +118 -0
- data/lib/ronin/ui/output/terminal/raw.rb +103 -0
- data/lib/ronin/ui/shell.rb +219 -0
- data/ronin-support.gemspec +1 -1
- data/spec/extensions/enumerable_spec.rb +24 -0
- data/spec/extensions/file_spec.rb +39 -0
- data/spec/extensions/ip_addr_spec.rb +6 -0
- data/spec/extensions/resolv_spec.rb +18 -0
- data/spec/formatting/html/integer_spec.rb +2 -2
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +55 -0
- data/spec/formatting/text/string_spec.rb +110 -0
- data/spec/network/ssl_spec.rb +10 -4
- data/spec/ui/classes/test_shell.rb +22 -0
- data/spec/ui/output_spec.rb +32 -0
- data/spec/ui/shell_spec.rb +79 -0
- metadata +132 -90
@@ -0,0 +1,331 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/network/tcp'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
23
|
+
|
24
|
+
require 'parameters'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Network
|
28
|
+
module Mixins
|
29
|
+
#
|
30
|
+
# Adds TCP convenience methods and connection parameters to a class.
|
31
|
+
#
|
32
|
+
# Defines the following parameters:
|
33
|
+
#
|
34
|
+
# * `host` (`String`) - TCP host.
|
35
|
+
# * `port` (`Integer`) - TCP port.
|
36
|
+
# * `local_host` (`String`) - TCP local host.
|
37
|
+
# * `local_port` (`Integer`) - TCP local port.
|
38
|
+
# * `server_host` (`String`) - TCP server host.
|
39
|
+
# * `server_port` (`Integer`) - TCP server port.
|
40
|
+
#
|
41
|
+
module TCP
|
42
|
+
include Mixin
|
43
|
+
|
44
|
+
mixin UI::Output::Helpers, Parameters
|
45
|
+
|
46
|
+
mixin do
|
47
|
+
# TCP host
|
48
|
+
parameter :host, :type => String,
|
49
|
+
:description => 'TCP host'
|
50
|
+
|
51
|
+
# TCP port
|
52
|
+
parameter :port, :type => Integer,
|
53
|
+
:description => 'TCP port'
|
54
|
+
|
55
|
+
# TCP local host
|
56
|
+
parameter :local_host, :type => String,
|
57
|
+
:description => 'TCP local host'
|
58
|
+
|
59
|
+
# TCP local port
|
60
|
+
parameter :local_port, :type => Integer,
|
61
|
+
:description => 'TCP local port'
|
62
|
+
|
63
|
+
# TCP server host
|
64
|
+
parameter :server_host, :type => String,
|
65
|
+
:description => 'TCP server host'
|
66
|
+
|
67
|
+
# TCP server port
|
68
|
+
parameter :server_port, :type => Integer,
|
69
|
+
:description => 'TCP server port'
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
#
|
75
|
+
# Opens a TCP connection to the host and port specified by the
|
76
|
+
# `host` and `port` parameters. If the `local_host` and
|
77
|
+
# `local_port` parameters are set, they will be used for
|
78
|
+
# the local host and port of the TCP connection.
|
79
|
+
#
|
80
|
+
# @yield [socket]
|
81
|
+
# If a block is given, it will be passed the newly created socket.
|
82
|
+
#
|
83
|
+
# @yieldparam [TCPsocket] socket
|
84
|
+
# The newly created TCPSocket object.
|
85
|
+
#
|
86
|
+
# @return [TCPSocket]
|
87
|
+
# The newly created TCPSocket object.
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# tcp_connect # => TCPSocket
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# tcp_connect do |sock|
|
94
|
+
# sock.write("GET /\n\n")
|
95
|
+
# puts sock.readlines
|
96
|
+
# sock.close
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# @api public
|
100
|
+
#
|
101
|
+
def tcp_connect(&block)
|
102
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
103
|
+
|
104
|
+
return ::Net.tcp_connect(self.host,self.port,self.local_host,self.local_port,&block)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Connects to the host and port specified by the `host` and `port`
|
109
|
+
# parameters, then sends the given data.
|
110
|
+
#
|
111
|
+
# @param [String] data
|
112
|
+
# The data to send through the connection.
|
113
|
+
#
|
114
|
+
# @yield [socket]
|
115
|
+
# If a block is given, it will be passed the newly created socket.
|
116
|
+
#
|
117
|
+
# @yieldparam [TCPsocket] socket
|
118
|
+
# The newly created TCPSocket object.
|
119
|
+
#
|
120
|
+
# @return [TCPSocket]
|
121
|
+
# The newly created TCPSocket object.
|
122
|
+
#
|
123
|
+
# @api public
|
124
|
+
#
|
125
|
+
def tcp_connect_and_send(data,&block)
|
126
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
127
|
+
print_debug "Sending data: #{data.inspect}"
|
128
|
+
|
129
|
+
return ::Net.tcp_connect_and_send(data,self.host,self.port,self.local_host,self.local_port,&block)
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Creates a TCP session to the host and port specified by the
|
134
|
+
# `host` and `port` parameters.
|
135
|
+
#
|
136
|
+
# @yield [socket]
|
137
|
+
# If a block is given, it will be passed the newly created socket.
|
138
|
+
# After the block has returned, the socket will be closed.
|
139
|
+
#
|
140
|
+
# @yieldparam [TCPsocket] socket
|
141
|
+
# The newly created TCPSocket object.
|
142
|
+
#
|
143
|
+
# @return [nil]
|
144
|
+
#
|
145
|
+
# @api public
|
146
|
+
#
|
147
|
+
def tcp_session(&block)
|
148
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
149
|
+
|
150
|
+
Net.tcp_session(self.host,self.port,self.local_host,self.local_port,&block)
|
151
|
+
|
152
|
+
print_info "Disconnected from #{self.host}:#{self.port}"
|
153
|
+
return nil
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Connects to the host and port specified by the `host` and `port`
|
158
|
+
# parameters, reads the banner then closes the connection.
|
159
|
+
#
|
160
|
+
# @yield [banner]
|
161
|
+
# If a block is given, it will be passed the grabbed banner.
|
162
|
+
#
|
163
|
+
# @yieldparam [String] banner
|
164
|
+
# The grabbed banner.
|
165
|
+
#
|
166
|
+
# @return [String]
|
167
|
+
# The grabbed banner.
|
168
|
+
#
|
169
|
+
# @example
|
170
|
+
# tcp_banner
|
171
|
+
# # => "220 mx.google.com ESMTP c20sm3096959rvf.1"
|
172
|
+
#
|
173
|
+
# @api public
|
174
|
+
#
|
175
|
+
def tcp_banner(&block)
|
176
|
+
print_debug "Grabbing banner from #{self.host}:#{self.port}"
|
177
|
+
|
178
|
+
return ::Net.tcp_banner(self.host,self.port,self.local_host,self.local_port,&block)
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# Connects to the host and port specified by the `host` and `port`
|
183
|
+
# parameters, sends the given data and then disconnects.
|
184
|
+
#
|
185
|
+
# @return [true]
|
186
|
+
# The data was successfully sent.
|
187
|
+
#
|
188
|
+
# @example
|
189
|
+
# buffer = "GET /" + ('A' * 4096) + "\n\r"
|
190
|
+
# Net.tcp_send(buffer)
|
191
|
+
# # => true
|
192
|
+
#
|
193
|
+
# @api public
|
194
|
+
#
|
195
|
+
def tcp_send(data)
|
196
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
197
|
+
print_debug "Sending data: #{data.inspect}"
|
198
|
+
|
199
|
+
::Net.tcp_send(data,self.host,self.port,self.local_host,self.local_port)
|
200
|
+
|
201
|
+
print_info "Disconnected from #{self.host}:#{self.port}"
|
202
|
+
return true
|
203
|
+
end
|
204
|
+
|
205
|
+
#
|
206
|
+
# Creates a new TCPServer object listening on the `server_host`
|
207
|
+
# and `server_port` parameters.
|
208
|
+
#
|
209
|
+
# @yield [server]
|
210
|
+
# The given block will be passed the newly created server.
|
211
|
+
#
|
212
|
+
# @yieldparam [TCPServer] server
|
213
|
+
# The newly created server.
|
214
|
+
#
|
215
|
+
# @return [TCPServer]
|
216
|
+
# The newly created server.
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# tcp_server
|
220
|
+
#
|
221
|
+
# @api public
|
222
|
+
#
|
223
|
+
def tcp_server(&block)
|
224
|
+
if self.server_host
|
225
|
+
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
226
|
+
else
|
227
|
+
print_info "Listening on #{self.server_port} ..."
|
228
|
+
end
|
229
|
+
|
230
|
+
return ::Net.tcp_server(self.server_port,self.server_host,&block)
|
231
|
+
end
|
232
|
+
|
233
|
+
#
|
234
|
+
# Creates a new temporary TCPServer object listening on the
|
235
|
+
# `server_host` and `server_port` parameters.
|
236
|
+
#
|
237
|
+
# @yield [server]
|
238
|
+
# The given block will be passed the newly created server.
|
239
|
+
# When the block has finished, the server will be closed.
|
240
|
+
#
|
241
|
+
# @yieldparam [TCPServer] server
|
242
|
+
# The newly created server.
|
243
|
+
#
|
244
|
+
# @return [nil]
|
245
|
+
#
|
246
|
+
# @example
|
247
|
+
# tcp_server_session do |server|
|
248
|
+
# client1 = server.accept
|
249
|
+
# client2 = server.accept
|
250
|
+
#
|
251
|
+
# client2.write(server.read_line)
|
252
|
+
#
|
253
|
+
# client1.close
|
254
|
+
# client2.close
|
255
|
+
# end
|
256
|
+
#
|
257
|
+
# @api public
|
258
|
+
#
|
259
|
+
def tcp_server_session(&block)
|
260
|
+
if self.server_host
|
261
|
+
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
262
|
+
else
|
263
|
+
print_info "Listening on #{self.server_port} ..."
|
264
|
+
end
|
265
|
+
|
266
|
+
::Net.tcp_server_session(&block)
|
267
|
+
|
268
|
+
if self.server_host
|
269
|
+
print_info "Closed #{self.server_host}:#{self.server_port}"
|
270
|
+
else
|
271
|
+
print_info "Closed #{self.server_port}"
|
272
|
+
end
|
273
|
+
|
274
|
+
return nil
|
275
|
+
end
|
276
|
+
|
277
|
+
#
|
278
|
+
# Creates a new temporary TCPServer object listening on
|
279
|
+
# `server_host` and `server_port` parameters.
|
280
|
+
# The TCPServer will accepting one client, pass the newly connected
|
281
|
+
# client to a given block, disconnects the client and stops
|
282
|
+
# listening.
|
283
|
+
#
|
284
|
+
# @yield [client]
|
285
|
+
# The given block will be passed the newly connected client.
|
286
|
+
# When the block has finished, the newly connected client and
|
287
|
+
# the server will be closed.
|
288
|
+
#
|
289
|
+
# @yieldparam [TCPSocket] client
|
290
|
+
# The newly connected client.
|
291
|
+
#
|
292
|
+
# @return [nil]
|
293
|
+
#
|
294
|
+
# @example
|
295
|
+
# tcp_single_server do |client|
|
296
|
+
# client.puts 'lol'
|
297
|
+
# end
|
298
|
+
#
|
299
|
+
# @api public
|
300
|
+
#
|
301
|
+
def tcp_single_server(&block)
|
302
|
+
if self.server_host
|
303
|
+
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
304
|
+
else
|
305
|
+
print_info "Listening on #{self.server_port} ..."
|
306
|
+
end
|
307
|
+
|
308
|
+
::Net.tcp_single_server do |client|
|
309
|
+
client_addr = client.peeraddr
|
310
|
+
client_host = (client_addr[2] || client_addr[3])
|
311
|
+
client_port = client_addr[1]
|
312
|
+
|
313
|
+
print_info "Client connected #{client_host}:#{client_port}"
|
314
|
+
|
315
|
+
yield client if block_given?
|
316
|
+
|
317
|
+
print_info "Disconnecting client #{client_host}:#{client_port}"
|
318
|
+
end
|
319
|
+
|
320
|
+
if self.server_host
|
321
|
+
print_info "Closed #{self.server_host}:#{self.server_port}"
|
322
|
+
else
|
323
|
+
print_info "Closed #{self.server_port}"
|
324
|
+
end
|
325
|
+
|
326
|
+
return nil
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/network/telnet'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
23
|
+
|
24
|
+
require 'parameters'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Network
|
28
|
+
module Mixins
|
29
|
+
#
|
30
|
+
# Adds Telnet convenience methods and connection parameters to a
|
31
|
+
# class.
|
32
|
+
#
|
33
|
+
# Defines the following parameters:
|
34
|
+
#
|
35
|
+
# * `host` (`String`) - Telnet host.
|
36
|
+
# * `port` (`Integer`) - Telnet port.
|
37
|
+
# * `telnet_user` (`String`) - Telnet user to login as.
|
38
|
+
# * `telnet_password` (`String`) - Telnet password to login with.
|
39
|
+
# * `telnet_proxy` (`String`) - Telnet proxy.
|
40
|
+
# * `telnet_ssl` (`Boolean`) - Enable Telnet over SSL. Defaults to `true`.
|
41
|
+
#
|
42
|
+
module Telnet
|
43
|
+
include Mixin
|
44
|
+
|
45
|
+
mixin UI::Output::Helpers, Parameters
|
46
|
+
|
47
|
+
mixin do
|
48
|
+
# Telnet host
|
49
|
+
parameter :host, :type => String,
|
50
|
+
:description => 'Telnet host'
|
51
|
+
|
52
|
+
# Telnet port
|
53
|
+
parameter :port, :type => Integer,
|
54
|
+
:description => 'Telnet port'
|
55
|
+
|
56
|
+
# Telnet user
|
57
|
+
parameter :telnet_user, :type => String,
|
58
|
+
:description => 'Telnet user to login as'
|
59
|
+
|
60
|
+
# Telnet password
|
61
|
+
parameter :telnet_password, :type => String,
|
62
|
+
:description => 'Telnet password to login with'
|
63
|
+
|
64
|
+
# Telnet proxy
|
65
|
+
parameter :telnet_proxy, :description => 'Telnet proxy'
|
66
|
+
|
67
|
+
# Enable Telnet SSL
|
68
|
+
parameter :telnet_ssl, :type => true,
|
69
|
+
:description => 'Enable Telnet over SSL'
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
#
|
75
|
+
# Creates a connection to a Telnet server. The `host`, `port`,
|
76
|
+
# `telnet_user`, `telnet_password`, `telnet_proxy` and
|
77
|
+
# `telnet_ssl` parameters will also be used to connect to the
|
78
|
+
# Telnet server.
|
79
|
+
#
|
80
|
+
# @param [Hash] options
|
81
|
+
# Additional options.
|
82
|
+
#
|
83
|
+
# @option options [Integer] :port (Ronin::Network::Telnet.default_port)
|
84
|
+
# The port to connect to.
|
85
|
+
#
|
86
|
+
# @option options [Boolean] :binmode
|
87
|
+
# Indicates that newline substitution shall not be performed.
|
88
|
+
#
|
89
|
+
# @option options [String] :output_log
|
90
|
+
# The name of the file to write connection status messages
|
91
|
+
# and all received traffic to.
|
92
|
+
#
|
93
|
+
# @option options [String] :dump_log
|
94
|
+
# Similar to the `:output_log` option, but connection output
|
95
|
+
# is also written in hexdump format.
|
96
|
+
#
|
97
|
+
# @option options [Regexp] :prompt (Ronin::Network::Telnet.default_prompt)
|
98
|
+
# A regular expression matching the host command-line prompt
|
99
|
+
# sequence, used to determine when a command has finished.
|
100
|
+
#
|
101
|
+
# @option options [Boolean] :telnet (true)
|
102
|
+
# Indicates that the connection shall behave as a telnet
|
103
|
+
# connection.
|
104
|
+
#
|
105
|
+
# @option options [Boolean] :plain
|
106
|
+
# Indicates that the connection shall behave as a normal TCP
|
107
|
+
# connection.
|
108
|
+
#
|
109
|
+
# @option options [Integer] :timeout (Ronin::Network::Telnet.default_timeout)
|
110
|
+
# The number of seconds to wait before timing out both the
|
111
|
+
# initial attempt to connect to host, and all attempts to read
|
112
|
+
# data from the host.
|
113
|
+
#
|
114
|
+
# @option options [Integer] :wait_time
|
115
|
+
# The amount of time to wait after seeing what looks like
|
116
|
+
# a prompt.
|
117
|
+
#
|
118
|
+
# @option options [Net::Telnet, IO] :proxy (Ronin::Network::Telnet.proxy)
|
119
|
+
# A proxy object to used instead of opening a direct connection
|
120
|
+
# to the host.
|
121
|
+
#
|
122
|
+
# @option options [String] :user
|
123
|
+
# The user to login as.
|
124
|
+
#
|
125
|
+
# @option options [String] :password
|
126
|
+
# The password to login with.
|
127
|
+
#
|
128
|
+
# @yield [connection]
|
129
|
+
# If a block is given, it will be passed the newly created
|
130
|
+
# Telnet connection.
|
131
|
+
#
|
132
|
+
# @yieldparam [Net::Telnet] connection
|
133
|
+
# The newly created Telnet connection.
|
134
|
+
#
|
135
|
+
# @return [Net::Telnet]
|
136
|
+
# The Telnet session
|
137
|
+
#
|
138
|
+
# @example
|
139
|
+
# telnet_connect
|
140
|
+
# # => Net::Telnet
|
141
|
+
#
|
142
|
+
# @api public
|
143
|
+
#
|
144
|
+
def telnet_connect(options={},&block)
|
145
|
+
options[:port] ||= self.port
|
146
|
+
options[:user] ||= self.telnet_user
|
147
|
+
options[:password] ||= self.telnet_password
|
148
|
+
|
149
|
+
options[:proxy] ||= self.telnet_proxy
|
150
|
+
options[:ssl] ||= self.telnet_ssl
|
151
|
+
|
152
|
+
if self.port
|
153
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
154
|
+
else
|
155
|
+
print_info "Connecting to #{self.host} ..."
|
156
|
+
end
|
157
|
+
|
158
|
+
return ::Net.telnet_connect(self.host,options,&block)
|
159
|
+
end
|
160
|
+
|
161
|
+
#
|
162
|
+
# Starts a session with a Telnet server. The `host`, `port`,
|
163
|
+
# `telnet_user`, `telnet_password`, `telnet_proxy` and
|
164
|
+
# `telnet_ssl` parameters will also be used to connect to the
|
165
|
+
# Telnet server.
|
166
|
+
#
|
167
|
+
# @yield [session]
|
168
|
+
# If a block is given, it will be passed the newly created
|
169
|
+
# Telnet session. After the block has returned, the Telnet
|
170
|
+
# session will be closed.
|
171
|
+
#
|
172
|
+
# @yieldparam [Net::Telnet] session
|
173
|
+
# The newly created Telnet session.
|
174
|
+
#
|
175
|
+
# @example
|
176
|
+
# telnet_session do |movie|
|
177
|
+
# movie.each_line { |line| puts line }
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# @see telnet_connect
|
181
|
+
#
|
182
|
+
# @api public
|
183
|
+
#
|
184
|
+
def telnet_session(options={},&block)
|
185
|
+
return telnet_connect(options) do |sess|
|
186
|
+
yield sess if block_given?
|
187
|
+
sess.close
|
188
|
+
|
189
|
+
if self.port
|
190
|
+
print_info "Disconnecting to #{self.host}:#{self.port}"
|
191
|
+
else
|
192
|
+
print_info "Disconnecting to #{self.host}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|