rubysl-net-telnet 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -6
- data/lib/rubysl/net/telnet/telnet.rb +129 -122
- data/lib/rubysl/net/telnet/version.rb +1 -1
- data/rubysl-net-telnet.gemspec +1 -2
- metadata +2 -17
- data/lib/net/telnets.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8967a940f0b7bd40863d0c33da78c9b4695c9620
|
4
|
+
data.tar.gz: 9f57926d7208c5c1a112f27c63fbb63988ac2e93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84a1ed324893d9a06243a9d69169e8c80d95f3920bb94a6c1e17afef00f0edef341fb815ab5f15c398e3bcc2fa22df4a9b3ff5443beb4fc955ec7fc9749ae7c9
|
7
|
+
data.tar.gz: 7293c743dc6834d10de079127fb578fd8ea2a59f78d4bc67afd949a5557bfdf97f874422d878f5b0cc8e0a17cb6acdc484ec4abaa627170a26d3e8993497a467
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# = net/telnet.rb - Simple Telnet Client Library
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Author:: Wakou Aoyama <wakou@ruby-lang.org>
|
4
|
-
# Documentation:: William Webber and Wakou Aoyama
|
4
|
+
# Documentation:: William Webber and Wakou Aoyama
|
5
5
|
#
|
6
6
|
# This file holds the class Net::Telnet, which provides client-side
|
7
7
|
# telnet functionality.
|
@@ -9,11 +9,9 @@
|
|
9
9
|
# For documentation, see Net::Telnet.
|
10
10
|
#
|
11
11
|
|
12
|
-
require "
|
13
|
-
require "delegate"
|
14
|
-
require "timeout"
|
12
|
+
require "net/protocol"
|
15
13
|
require "English"
|
16
|
-
|
14
|
+
|
17
15
|
module Net
|
18
16
|
|
19
17
|
#
|
@@ -50,11 +48,11 @@ module Net
|
|
50
48
|
# have to handle authentication yourself.
|
51
49
|
#
|
52
50
|
# For some protocols, it will be possible to specify the +Prompt+
|
53
|
-
# option once when you create the Telnet object and use #cmd() calls;
|
51
|
+
# option once when you create the Telnet object and use #cmd() calls;
|
54
52
|
# for others, you will have to specify the response sequence to
|
55
53
|
# look for as the Match option to every #cmd() call, or call
|
56
|
-
# #puts() and #waitfor() directly; for yet others, you will have
|
57
|
-
# to use #sysread() instead of #waitfor() and parse server
|
54
|
+
# #puts() and #waitfor() directly; for yet others, you will have
|
55
|
+
# to use #sysread() instead of #waitfor() and parse server
|
58
56
|
# responses yourself.
|
59
57
|
#
|
60
58
|
# It is worth noting that when you create a new Net::Telnet object,
|
@@ -63,21 +61,21 @@ module Net
|
|
63
61
|
# to already open sockets, or to any read-write IO object. This
|
64
62
|
# can be useful, for instance, for setting up a test fixture for
|
65
63
|
# unit testing.
|
66
|
-
#
|
64
|
+
#
|
67
65
|
# == Examples
|
68
|
-
#
|
66
|
+
#
|
69
67
|
# === Log in and send a command, echoing all output to stdout
|
70
|
-
#
|
68
|
+
#
|
71
69
|
# localhost = Net::Telnet::new("Host" => "localhost",
|
72
70
|
# "Timeout" => 10,
|
73
71
|
# "Prompt" => /[$%#>] \z/n)
|
74
72
|
# localhost.login("username", "password") { |c| print c }
|
75
73
|
# localhost.cmd("command") { |c| print c }
|
76
74
|
# localhost.close
|
77
|
-
#
|
78
|
-
#
|
75
|
+
#
|
76
|
+
#
|
79
77
|
# === Check a POP server to see if you have mail
|
80
|
-
#
|
78
|
+
#
|
81
79
|
# pop = Net::Telnet::new("Host" => "your_destination_host_here",
|
82
80
|
# "Port" => 110,
|
83
81
|
# "Telnetmode" => false,
|
@@ -93,77 +91,77 @@ module Net
|
|
93
91
|
# of relevant RFCs, see
|
94
92
|
# http://www.omnifarious.org/~hopper/technical/telnet-rfc.html
|
95
93
|
#
|
96
|
-
class Telnet
|
94
|
+
class Telnet
|
97
95
|
|
98
96
|
# :stopdoc:
|
99
97
|
IAC = 255.chr # "\377" # "\xff" # interpret as command
|
100
|
-
DONT = 254.chr # "\376" # "\xfe" # you are not to use option
|
101
|
-
DO = 253.chr # "\375" # "\xfd" # please, you use option
|
102
|
-
WONT = 252.chr # "\374" # "\xfc" # I won't use option
|
103
|
-
WILL = 251.chr # "\373" # "\xfb" # I will use option
|
104
|
-
SB = 250.chr # "\372" # "\xfa" # interpret as subnegotiation
|
105
|
-
GA = 249.chr # "\371" # "\xf9" # you may reverse the line
|
106
|
-
EL = 248.chr # "\370" # "\xf8" # erase the current line
|
107
|
-
EC = 247.chr # "\367" # "\xf7" # erase the current character
|
108
|
-
AYT = 246.chr # "\366" # "\xf6" # are you there
|
109
|
-
AO = 245.chr # "\365" # "\xf5" # abort output--but let prog finish
|
110
|
-
IP = 244.chr # "\364" # "\xf4" # interrupt process--permanently
|
111
|
-
BREAK = 243.chr # "\363" # "\xf3" # break
|
112
|
-
DM = 242.chr # "\362" # "\xf2" # data mark--for connect. cleaning
|
113
|
-
NOP = 241.chr # "\361" # "\xf1" # nop
|
114
|
-
SE = 240.chr # "\360" # "\xf0" # end sub negotiation
|
115
|
-
EOR = 239.chr # "\357" # "\xef" # end of record (transparent mode)
|
116
|
-
ABORT = 238.chr # "\356" # "\xee" # Abort process
|
117
|
-
SUSP = 237.chr # "\355" # "\xed" # Suspend process
|
118
|
-
EOF = 236.chr # "\354" # "\xec" # End of file
|
119
|
-
SYNCH = 242.chr # "\362" # "\xf2" # for telfunc calls
|
120
|
-
|
121
|
-
OPT_BINARY = 0.chr # "\000" # "\x00" # Binary Transmission
|
122
|
-
OPT_ECHO = 1.chr # "\001" # "\x01" # Echo
|
123
|
-
OPT_RCP = 2.chr # "\002" # "\x02" # Reconnection
|
124
|
-
OPT_SGA = 3.chr # "\003" # "\x03" # Suppress Go Ahead
|
125
|
-
OPT_NAMS = 4.chr # "\004" # "\x04" # Approx Message Size Negotiation
|
126
|
-
OPT_STATUS = 5.chr # "\005" # "\x05" # Status
|
127
|
-
OPT_TM = 6.chr # "\006" # "\x06" # Timing Mark
|
128
|
-
OPT_RCTE = 7.chr # "\a" # "\x07" # Remote Controlled Trans and Echo
|
129
|
-
OPT_NAOL = 8.chr # "\010" # "\x08" # Output Line Width
|
130
|
-
OPT_NAOP = 9.chr # "\t" # "\x09" # Output Page Size
|
131
|
-
OPT_NAOCRD = 10.chr # "\n" # "\x0a" # Output Carriage-Return Disposition
|
132
|
-
OPT_NAOHTS = 11.chr # "\v" # "\x0b" # Output Horizontal Tab Stops
|
133
|
-
OPT_NAOHTD = 12.chr # "\f" # "\x0c" # Output Horizontal Tab Disposition
|
134
|
-
OPT_NAOFFD = 13.chr # "\r" # "\x0d" # Output Formfeed Disposition
|
135
|
-
OPT_NAOVTS = 14.chr # "\016" # "\x0e" # Output Vertical Tabstops
|
136
|
-
OPT_NAOVTD = 15.chr # "\017" # "\x0f" # Output Vertical Tab Disposition
|
137
|
-
OPT_NAOLFD = 16.chr # "\020" # "\x10" # Output Linefeed Disposition
|
138
|
-
OPT_XASCII = 17.chr # "\021" # "\x11" # Extended ASCII
|
139
|
-
OPT_LOGOUT = 18.chr # "\022" # "\x12" # Logout
|
140
|
-
OPT_BM = 19.chr # "\023" # "\x13" # Byte Macro
|
141
|
-
OPT_DET = 20.chr # "\024" # "\x14" # Data Entry Terminal
|
142
|
-
OPT_SUPDUP = 21.chr # "\025" # "\x15" # SUPDUP
|
143
|
-
OPT_SUPDUPOUTPUT = 22.chr # "\026" # "\x16" # SUPDUP Output
|
144
|
-
OPT_SNDLOC = 23.chr # "\027" # "\x17" # Send Location
|
145
|
-
OPT_TTYPE = 24.chr # "\030" # "\x18" # Terminal Type
|
146
|
-
OPT_EOR = 25.chr # "\031" # "\x19" # End of Record
|
147
|
-
OPT_TUID = 26.chr # "\032" # "\x1a" # TACACS User Identification
|
148
|
-
OPT_OUTMRK = 27.chr # "\e" # "\x1b" # Output Marking
|
149
|
-
OPT_TTYLOC = 28.chr # "\034" # "\x1c" # Terminal Location Number
|
150
|
-
OPT_3270REGIME = 29.chr # "\035" # "\x1d" # Telnet 3270 Regime
|
151
|
-
OPT_X3PAD = 30.chr # "\036" # "\x1e" # X.3 PAD
|
152
|
-
OPT_NAWS = 31.chr # "\037" # "\x1f" # Negotiate About Window Size
|
153
|
-
OPT_TSPEED = 32.chr # " " # "\x20" # Terminal Speed
|
154
|
-
OPT_LFLOW = 33.chr # "!" # "\x21" # Remote Flow Control
|
155
|
-
OPT_LINEMODE = 34.chr # "\"" # "\x22" # Linemode
|
156
|
-
OPT_XDISPLOC = 35.chr # "#" # "\x23" # X Display Location
|
157
|
-
OPT_OLD_ENVIRON = 36.chr # "$" # "\x24" # Environment Option
|
158
|
-
OPT_AUTHENTICATION = 37.chr # "%" # "\x25" # Authentication Option
|
159
|
-
OPT_ENCRYPT = 38.chr # "&" # "\x26" # Encryption Option
|
160
|
-
OPT_NEW_ENVIRON = 39.chr # "'" # "\x27" # New Environment Option
|
161
|
-
OPT_EXOPL = 255.chr # "\377" # "\xff" # Extended-Options-List
|
162
|
-
|
163
|
-
NULL = "\000"
|
164
|
-
CR = "\015"
|
165
|
-
LF = "\012"
|
166
|
-
EOL = CR + LF
|
98
|
+
DONT = 254.chr # "\376" # "\xfe" # you are not to use option
|
99
|
+
DO = 253.chr # "\375" # "\xfd" # please, you use option
|
100
|
+
WONT = 252.chr # "\374" # "\xfc" # I won't use option
|
101
|
+
WILL = 251.chr # "\373" # "\xfb" # I will use option
|
102
|
+
SB = 250.chr # "\372" # "\xfa" # interpret as subnegotiation
|
103
|
+
GA = 249.chr # "\371" # "\xf9" # you may reverse the line
|
104
|
+
EL = 248.chr # "\370" # "\xf8" # erase the current line
|
105
|
+
EC = 247.chr # "\367" # "\xf7" # erase the current character
|
106
|
+
AYT = 246.chr # "\366" # "\xf6" # are you there
|
107
|
+
AO = 245.chr # "\365" # "\xf5" # abort output--but let prog finish
|
108
|
+
IP = 244.chr # "\364" # "\xf4" # interrupt process--permanently
|
109
|
+
BREAK = 243.chr # "\363" # "\xf3" # break
|
110
|
+
DM = 242.chr # "\362" # "\xf2" # data mark--for connect. cleaning
|
111
|
+
NOP = 241.chr # "\361" # "\xf1" # nop
|
112
|
+
SE = 240.chr # "\360" # "\xf0" # end sub negotiation
|
113
|
+
EOR = 239.chr # "\357" # "\xef" # end of record (transparent mode)
|
114
|
+
ABORT = 238.chr # "\356" # "\xee" # Abort process
|
115
|
+
SUSP = 237.chr # "\355" # "\xed" # Suspend process
|
116
|
+
EOF = 236.chr # "\354" # "\xec" # End of file
|
117
|
+
SYNCH = 242.chr # "\362" # "\xf2" # for telfunc calls
|
118
|
+
|
119
|
+
OPT_BINARY = 0.chr # "\000" # "\x00" # Binary Transmission
|
120
|
+
OPT_ECHO = 1.chr # "\001" # "\x01" # Echo
|
121
|
+
OPT_RCP = 2.chr # "\002" # "\x02" # Reconnection
|
122
|
+
OPT_SGA = 3.chr # "\003" # "\x03" # Suppress Go Ahead
|
123
|
+
OPT_NAMS = 4.chr # "\004" # "\x04" # Approx Message Size Negotiation
|
124
|
+
OPT_STATUS = 5.chr # "\005" # "\x05" # Status
|
125
|
+
OPT_TM = 6.chr # "\006" # "\x06" # Timing Mark
|
126
|
+
OPT_RCTE = 7.chr # "\a" # "\x07" # Remote Controlled Trans and Echo
|
127
|
+
OPT_NAOL = 8.chr # "\010" # "\x08" # Output Line Width
|
128
|
+
OPT_NAOP = 9.chr # "\t" # "\x09" # Output Page Size
|
129
|
+
OPT_NAOCRD = 10.chr # "\n" # "\x0a" # Output Carriage-Return Disposition
|
130
|
+
OPT_NAOHTS = 11.chr # "\v" # "\x0b" # Output Horizontal Tab Stops
|
131
|
+
OPT_NAOHTD = 12.chr # "\f" # "\x0c" # Output Horizontal Tab Disposition
|
132
|
+
OPT_NAOFFD = 13.chr # "\r" # "\x0d" # Output Formfeed Disposition
|
133
|
+
OPT_NAOVTS = 14.chr # "\016" # "\x0e" # Output Vertical Tabstops
|
134
|
+
OPT_NAOVTD = 15.chr # "\017" # "\x0f" # Output Vertical Tab Disposition
|
135
|
+
OPT_NAOLFD = 16.chr # "\020" # "\x10" # Output Linefeed Disposition
|
136
|
+
OPT_XASCII = 17.chr # "\021" # "\x11" # Extended ASCII
|
137
|
+
OPT_LOGOUT = 18.chr # "\022" # "\x12" # Logout
|
138
|
+
OPT_BM = 19.chr # "\023" # "\x13" # Byte Macro
|
139
|
+
OPT_DET = 20.chr # "\024" # "\x14" # Data Entry Terminal
|
140
|
+
OPT_SUPDUP = 21.chr # "\025" # "\x15" # SUPDUP
|
141
|
+
OPT_SUPDUPOUTPUT = 22.chr # "\026" # "\x16" # SUPDUP Output
|
142
|
+
OPT_SNDLOC = 23.chr # "\027" # "\x17" # Send Location
|
143
|
+
OPT_TTYPE = 24.chr # "\030" # "\x18" # Terminal Type
|
144
|
+
OPT_EOR = 25.chr # "\031" # "\x19" # End of Record
|
145
|
+
OPT_TUID = 26.chr # "\032" # "\x1a" # TACACS User Identification
|
146
|
+
OPT_OUTMRK = 27.chr # "\e" # "\x1b" # Output Marking
|
147
|
+
OPT_TTYLOC = 28.chr # "\034" # "\x1c" # Terminal Location Number
|
148
|
+
OPT_3270REGIME = 29.chr # "\035" # "\x1d" # Telnet 3270 Regime
|
149
|
+
OPT_X3PAD = 30.chr # "\036" # "\x1e" # X.3 PAD
|
150
|
+
OPT_NAWS = 31.chr # "\037" # "\x1f" # Negotiate About Window Size
|
151
|
+
OPT_TSPEED = 32.chr # " " # "\x20" # Terminal Speed
|
152
|
+
OPT_LFLOW = 33.chr # "!" # "\x21" # Remote Flow Control
|
153
|
+
OPT_LINEMODE = 34.chr # "\"" # "\x22" # Linemode
|
154
|
+
OPT_XDISPLOC = 35.chr # "#" # "\x23" # X Display Location
|
155
|
+
OPT_OLD_ENVIRON = 36.chr # "$" # "\x24" # Environment Option
|
156
|
+
OPT_AUTHENTICATION = 37.chr # "%" # "\x25" # Authentication Option
|
157
|
+
OPT_ENCRYPT = 38.chr # "&" # "\x26" # Encryption Option
|
158
|
+
OPT_NEW_ENVIRON = 39.chr # "'" # "\x27" # New Environment Option
|
159
|
+
OPT_EXOPL = 255.chr # "\377" # "\xff" # Extended-Options-List
|
160
|
+
|
161
|
+
NULL = "\000"
|
162
|
+
CR = "\015"
|
163
|
+
LF = "\012"
|
164
|
+
EOL = CR + LF
|
167
165
|
REVISION = '$Id$'
|
168
166
|
# :startdoc:
|
169
167
|
|
@@ -174,13 +172,13 @@ module Net
|
|
174
172
|
# provided: see below). If a block is provided, it is yielded
|
175
173
|
# status messages on the attempt to connect to the server, of
|
176
174
|
# the form:
|
177
|
-
#
|
175
|
+
#
|
178
176
|
# Trying localhost...
|
179
177
|
# Connected to localhost.
|
180
178
|
#
|
181
179
|
# +options+ is a hash of options. The following example lists
|
182
180
|
# all options and their default values.
|
183
|
-
#
|
181
|
+
#
|
184
182
|
# host = Net::Telnet::new(
|
185
183
|
# "Host" => "localhost", # default: "localhost"
|
186
184
|
# "Port" => 23, # default: 23
|
@@ -198,16 +196,16 @@ module Net
|
|
198
196
|
#
|
199
197
|
# The options have the following meanings:
|
200
198
|
#
|
201
|
-
# Host:: the hostname or IP address of the host to connect to, as a String.
|
199
|
+
# Host:: the hostname or IP address of the host to connect to, as a String.
|
202
200
|
# Defaults to "localhost".
|
203
201
|
#
|
204
202
|
# Port:: the port to connect to. Defaults to 23.
|
205
203
|
#
|
206
|
-
# Binmode:: if false (the default), newline substitution is performed.
|
204
|
+
# Binmode:: if false (the default), newline substitution is performed.
|
207
205
|
# Outgoing LF is
|
208
206
|
# converted to CRLF, and incoming CRLF is converted to LF. If
|
209
207
|
# true, this substitution is not performed. This value can
|
210
|
-
# also be set with the #binmode() method. The
|
208
|
+
# also be set with the #binmode() method. The
|
211
209
|
# outgoing conversion only applies to the #puts() and #print()
|
212
210
|
# methods, not the #write() method. The precise nature of
|
213
211
|
# the newline conversion is also affected by the telnet options
|
@@ -217,13 +215,13 @@ module Net
|
|
217
215
|
# and all received traffic to. In the case of a proper
|
218
216
|
# Telnet session, this will include the client input as
|
219
217
|
# echoed by the host; otherwise, it only includes server
|
220
|
-
# responses. Output is appended verbatim to this file.
|
218
|
+
# responses. Output is appended verbatim to this file.
|
221
219
|
# By default, no output log is kept.
|
222
220
|
#
|
223
221
|
# Dump_log:: as for Output_log, except that output is written in hexdump
|
224
222
|
# format (16 bytes per line as hex pairs, followed by their
|
225
223
|
# printable equivalent), with connection status messages
|
226
|
-
# preceded by '#', sent traffic preceded by '>', and
|
224
|
+
# preceded by '#', sent traffic preceded by '>', and
|
227
225
|
# received traffic preceded by '<'. By default, not dump log
|
228
226
|
# is kept.
|
229
227
|
#
|
@@ -233,7 +231,7 @@ module Net
|
|
233
231
|
# ready to receive a new command. By default, this regular
|
234
232
|
# expression is /[$%#>] \z/n.
|
235
233
|
#
|
236
|
-
# Telnetmode:: a boolean value, true by default. In telnet mode,
|
234
|
+
# Telnetmode:: a boolean value, true by default. In telnet mode,
|
237
235
|
# traffic received from the host is parsed for special
|
238
236
|
# command sequences, and these sequences are escaped
|
239
237
|
# in outgoing traffic sent using #puts() or #print()
|
@@ -245,21 +243,21 @@ module Net
|
|
245
243
|
#
|
246
244
|
# Timeout:: the number of seconds to wait before timing out both the
|
247
245
|
# initial attempt to connect to host (in this constructor),
|
248
|
-
# and all attempts to read data
|
249
|
-
#
|
250
|
-
#
|
246
|
+
# which raises a Net::OpenTimeout, and all attempts to read data
|
247
|
+
# from the host, which raises a Net::ReadTimeout (in #waitfor(),
|
248
|
+
# #cmd(), and #login()). The default value is 10 seconds.
|
251
249
|
# You can disable the timeout by setting this value to false.
|
252
250
|
# In this case, the connect attempt will eventually timeout
|
253
251
|
# on the underlying connect(2) socket call with an
|
254
252
|
# Errno::ETIMEDOUT error (but generally only after a few
|
255
253
|
# minutes), but other attempts to read data from the host
|
256
|
-
# will
|
254
|
+
# will hang indefinitely if no data is forthcoming.
|
257
255
|
#
|
258
|
-
# Waittime:: the amount of time to wait after seeing what looks like a
|
256
|
+
# Waittime:: the amount of time to wait after seeing what looks like a
|
259
257
|
# prompt (that is, received data that matches the Prompt
|
260
258
|
# option regular expression) to see if more data arrives.
|
261
259
|
# If more data does arrive in this time, Net::Telnet assumes
|
262
|
-
# that what it saw was not really a prompt. This is to try to
|
260
|
+
# that what it saw was not really a prompt. This is to try to
|
263
261
|
# avoid false matches, but it can also lead to missing real
|
264
262
|
# prompts (if, for instance, a background process writes to
|
265
263
|
# the terminal soon after the prompt is displayed). By
|
@@ -267,12 +265,12 @@ module Net
|
|
267
265
|
#
|
268
266
|
# Proxy:: a proxy object to used instead of opening a direct connection
|
269
267
|
# to the host. Must be either another Net::Telnet object or
|
270
|
-
# an IO object. If it is another Net::Telnet object, this
|
268
|
+
# an IO object. If it is another Net::Telnet object, this
|
271
269
|
# instance will use that one's socket for communication. If an
|
272
270
|
# IO object, it is used directly for communication. Any other
|
273
271
|
# kind of object will cause an error to be raised.
|
274
272
|
#
|
275
|
-
def initialize(options) # :yield: mesg
|
273
|
+
def initialize(options) # :yield: mesg
|
276
274
|
@options = options
|
277
275
|
@options["Host"] = "localhost" unless @options.has_key?("Host")
|
278
276
|
@options["Port"] = 23 unless @options.has_key?("Port")
|
@@ -280,7 +278,7 @@ module Net
|
|
280
278
|
@options["Timeout"] = 10 unless @options.has_key?("Timeout")
|
281
279
|
@options["Waittime"] = 0 unless @options.has_key?("Waittime")
|
282
280
|
unless @options.has_key?("Binmode")
|
283
|
-
@options["Binmode"] = false
|
281
|
+
@options["Binmode"] = false
|
284
282
|
else
|
285
283
|
unless (true == @options["Binmode"] or false == @options["Binmode"])
|
286
284
|
raise ArgumentError, "Binmode option must be true or false"
|
@@ -288,7 +286,7 @@ module Net
|
|
288
286
|
end
|
289
287
|
|
290
288
|
unless @options.has_key?("Telnetmode")
|
291
|
-
@options["Telnetmode"] = true
|
289
|
+
@options["Telnetmode"] = true
|
292
290
|
else
|
293
291
|
unless (true == @options["Telnetmode"] or false == @options["Telnetmode"])
|
294
292
|
raise ArgumentError, "Telnetmode option must be true or false"
|
@@ -348,12 +346,12 @@ module Net
|
|
348
346
|
if @options["Timeout"] == false
|
349
347
|
@sock = TCPSocket.open(@options["Host"], @options["Port"])
|
350
348
|
else
|
351
|
-
timeout(@options["Timeout"]) do
|
349
|
+
Timeout.timeout(@options["Timeout"], Net::OpenTimeout) do
|
352
350
|
@sock = TCPSocket.open(@options["Host"], @options["Port"])
|
353
351
|
end
|
354
352
|
end
|
355
|
-
rescue
|
356
|
-
raise
|
353
|
+
rescue Net::OpenTimeout
|
354
|
+
raise Net::OpenTimeout, "timed out while opening a connection to the host"
|
357
355
|
rescue
|
358
356
|
@log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
|
359
357
|
@dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
|
@@ -368,13 +366,12 @@ module Net
|
|
368
366
|
@dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
|
369
367
|
end
|
370
368
|
|
371
|
-
super(@sock)
|
372
369
|
end # initialize
|
373
370
|
|
374
371
|
# The socket the Telnet object is using. Note that this object becomes
|
375
372
|
# a delegate of the Telnet object, so normally you invoke its methods
|
376
373
|
# directly on the Telnet object.
|
377
|
-
attr :sock
|
374
|
+
attr :sock
|
378
375
|
|
379
376
|
# Set telnet command interpretation on (+mode+ == true) or off
|
380
377
|
# (+mode+ == false), or return the current value (+mode+ not
|
@@ -408,7 +405,7 @@ module Net
|
|
408
405
|
def binmode(mode = nil)
|
409
406
|
case mode
|
410
407
|
when nil
|
411
|
-
@options["Binmode"]
|
408
|
+
@options["Binmode"]
|
412
409
|
when true, false
|
413
410
|
@options["Binmode"] = mode
|
414
411
|
else
|
@@ -428,7 +425,7 @@ module Net
|
|
428
425
|
# Preprocess received data from the host.
|
429
426
|
#
|
430
427
|
# Performs newline conversion and detects telnet command sequences.
|
431
|
-
# Called automatically by #waitfor(). You should only use this
|
428
|
+
# Called automatically by #waitfor(). You should only use this
|
432
429
|
# method yourself if you have read input directly using sysread()
|
433
430
|
# or similar, and even then only if in telnet mode.
|
434
431
|
def preprocess(string)
|
@@ -438,6 +435,9 @@ module Net
|
|
438
435
|
# combine EOL into "\n"
|
439
436
|
string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
|
440
437
|
|
438
|
+
# remove NULL
|
439
|
+
string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
|
440
|
+
|
441
441
|
string.gsub(/#{IAC}(
|
442
442
|
[#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
|
443
443
|
[#{DO}#{DONT}#{WILL}#{WONT}]
|
@@ -491,9 +491,9 @@ module Net
|
|
491
491
|
# Read data from the host until a certain sequence is matched.
|
492
492
|
#
|
493
493
|
# If a block is given, the received data will be yielded as it
|
494
|
-
# is read in (not necessarily all in one go), or nil if EOF
|
494
|
+
# is read in (not necessarily all in one go), or nil if EOF
|
495
495
|
# occurs before any data is received. Whether a block is given
|
496
|
-
# or not, all data read will be returned in a single string, or again
|
496
|
+
# or not, all data read will be returned in a single string, or again
|
497
497
|
# nil if EOF occurs before any data is received. Note that
|
498
498
|
# received data includes the matched sequence we were looking for.
|
499
499
|
#
|
@@ -507,7 +507,7 @@ module Net
|
|
507
507
|
# into a regular expression. Used only if Match and
|
508
508
|
# Prompt are not specified.
|
509
509
|
# Timeout:: the number of seconds to wait for data from the host
|
510
|
-
# before raising a
|
510
|
+
# before raising a Timeout::Error. If set to false,
|
511
511
|
# no timeout will occur. If not specified, the
|
512
512
|
# Timeout option value specified when this instance
|
513
513
|
# was created will be used, or, failing that, the
|
@@ -524,7 +524,7 @@ module Net
|
|
524
524
|
# EOFError will be raised. Otherwise, defaults to the old
|
525
525
|
# behaviour that the function will return whatever data
|
526
526
|
# has been received already, or nil if nothing was received.
|
527
|
-
#
|
527
|
+
#
|
528
528
|
def waitfor(options) # :yield: recvdata
|
529
529
|
time_out = @options["Timeout"]
|
530
530
|
waittime = @options["Waittime"]
|
@@ -554,15 +554,15 @@ module Net
|
|
554
554
|
rest = ''
|
555
555
|
until(prompt === line and not IO::select([@sock], nil, nil, waittime))
|
556
556
|
unless IO::select([@sock], nil, nil, time_out)
|
557
|
-
raise
|
557
|
+
raise Net::ReadTimeout, "timed out while waiting for more data"
|
558
558
|
end
|
559
559
|
begin
|
560
560
|
c = @sock.readpartial(1024 * 1024)
|
561
561
|
@dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
|
562
562
|
if @options["Telnetmode"]
|
563
563
|
c = rest + c
|
564
|
-
if Integer(c.rindex(/#{IAC}#{SE}/no)) <
|
565
|
-
Integer(c.rindex(/#{IAC}#{SB}/no))
|
564
|
+
if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
|
565
|
+
Integer(c.rindex(/#{IAC}#{SB}/no) || 0)
|
566
566
|
buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
|
567
567
|
rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
|
568
568
|
elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
|
@@ -619,7 +619,7 @@ module Net
|
|
619
619
|
# Sends a string to the host.
|
620
620
|
#
|
621
621
|
# This does _not_ automatically append a newline to the string. Embedded
|
622
|
-
# newlines may be converted and telnet command sequences escaped
|
622
|
+
# newlines may be converted and telnet command sequences escaped
|
623
623
|
# depending upon the values of telnetmode, binmode, and telnet options
|
624
624
|
# set by the host.
|
625
625
|
def print(string)
|
@@ -654,7 +654,7 @@ module Net
|
|
654
654
|
# data until is sees the prompt or other matched sequence.
|
655
655
|
#
|
656
656
|
# If a block is given, the received data will be yielded to it as
|
657
|
-
# it is read in. Whether a block is given or not, the received data
|
657
|
+
# it is read in. Whether a block is given or not, the received data
|
658
658
|
# will be return as a string. Note that the received data includes
|
659
659
|
# the prompt and in most cases the host's echo of our command.
|
660
660
|
#
|
@@ -678,20 +678,22 @@ module Net
|
|
678
678
|
def cmd(options) # :yield: recvdata
|
679
679
|
match = @options["Prompt"]
|
680
680
|
time_out = @options["Timeout"]
|
681
|
+
fail_eof = @options["FailEOF"]
|
681
682
|
|
682
683
|
if options.kind_of?(Hash)
|
683
684
|
string = options["String"]
|
684
685
|
match = options["Match"] if options.has_key?("Match")
|
685
686
|
time_out = options["Timeout"] if options.has_key?("Timeout")
|
687
|
+
fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
|
686
688
|
else
|
687
689
|
string = options
|
688
690
|
end
|
689
691
|
|
690
692
|
self.puts(string)
|
691
693
|
if block_given?
|
692
|
-
waitfor({"Prompt" => match, "Timeout" => time_out}){|c| yield c }
|
694
|
+
waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
|
693
695
|
else
|
694
|
-
waitfor({"Prompt" => match, "Timeout" => time_out})
|
696
|
+
waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof})
|
695
697
|
end
|
696
698
|
end
|
697
699
|
|
@@ -699,7 +701,7 @@ module Net
|
|
699
701
|
#
|
700
702
|
# The username and password can either be provided as two string
|
701
703
|
# arguments in that order, or as a hash with keys "Name" and
|
702
|
-
# "Password".
|
704
|
+
# "Password".
|
703
705
|
#
|
704
706
|
# This method looks for the strings "login" and "Password" from the
|
705
707
|
# host to determine when to send the username and password. If the
|
@@ -723,8 +725,8 @@ module Net
|
|
723
725
|
if options.kind_of?(Hash)
|
724
726
|
username = options["Name"]
|
725
727
|
password = options["Password"]
|
726
|
-
|
727
|
-
|
728
|
+
login_prompt = options["LoginPrompt"] if options["LoginPrompt"]
|
729
|
+
password_prompt = options["PasswordPrompt"] if options["PasswordPrompt"]
|
728
730
|
else
|
729
731
|
username = options
|
730
732
|
end
|
@@ -751,6 +753,11 @@ module Net
|
|
751
753
|
line
|
752
754
|
end
|
753
755
|
|
756
|
+
# Closes the connection
|
757
|
+
def close
|
758
|
+
@sock.close
|
759
|
+
end
|
760
|
+
|
754
761
|
end # class Telnet
|
755
762
|
end # module Net
|
756
763
|
|
data/rubysl-net-telnet.gemspec
CHANGED
@@ -19,5 +19,4 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "rake", "~> 10.0"
|
21
21
|
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
-
|
23
|
-
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-net-telnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubysl-prettyprint
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.0'
|
69
55
|
description: Ruby standard library telnet.
|
70
56
|
email:
|
71
57
|
- brixen@gmail.com
|
@@ -80,7 +66,6 @@ files:
|
|
80
66
|
- README.md
|
81
67
|
- Rakefile
|
82
68
|
- lib/net/telnet.rb
|
83
|
-
- lib/net/telnets.rb
|
84
69
|
- lib/rubysl/net/telnet.rb
|
85
70
|
- lib/rubysl/net/telnet/telnet.rb
|
86
71
|
- lib/rubysl/net/telnet/version.rb
|
data/lib/net/telnets.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'openssl/net/telnets'
|