net-ping 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,67 @@
1
+ == 1.0.0 - 14-Jun-2005
2
+ * Renamed project from net-pingsimple to just net-ping.
3
+ * Added a PingHTTP subclass.
4
+ * Moved project to RubyForge.
5
+ * Added a gemspec.
6
+
7
+ == 0.3.1 - 9-Apr-2005
8
+ * Updated PingExternal to use win32/open3 on Win32 platforms.
9
+ * Minor error handling change for the PingSimple.econnrefused= method. It now
10
+ raises an ArgumentError if any values other than true or false are passed.
11
+ * PingSimple#warning and PingSimple#exception are now read-only methods.
12
+ * The warning and exception attributes are now reset to nil between each call
13
+ to ping.
14
+ * The data and data= methods are now unique to the PingUDP class.
15
+ * The time and time= methods have been changed to timeout and timeout=,
16
+ respectively.
17
+ * Removed the pingsimple.rd and pingsimple.html files. The pingsimple.txt file
18
+ has been reorganized and is now rdoc friendly.
19
+ * Added a few sample programs under the 'examples' directory.
20
+ * Some minor test updates and changes.
21
+ * Removed the INSTALL file. That information is now in the README file.
22
+ * Now requires Ruby 1.8.0 or later.
23
+
24
+ == 0.3.0 - 12-Feb-2004
25
+ * Fixed ping string for PingExternal class based on platform. The old
26
+ string was really only good for Linux and *BSD.
27
+ * Added Win32 support (requires win32_popen package).
28
+ * Added warranty info.
29
+
30
+ == 0.2.3 - 12-Aug-2003
31
+ * Fixed a bug in PingExternal that could consume file descriptors if used in a loop
32
+ * Added some initialization to avoid -w warnings
33
+ * Removed VERSION() class method. Use the constant instead
34
+ * Modified test suite slightly
35
+ * Moved rd2 docs to doc directory
36
+
37
+ == 0.2.2 - 3-Apr-2003
38
+ * Fixed handling of stdout in PingExternal
39
+
40
+ == 0.2.1 - 27-Mar-2003
41
+ * Fixed major bug with PingExternal class with regards to down hosts
42
+ * Exceptions and warnings from PingExternal are now chomp'd
43
+ * Modified test suite
44
+ * Doc updates
45
+
46
+ == 0.2.0 - 14-Feb-2003
47
+ * The default behavior of PingTCP with regards to ECONNREFUSED is now
48
+ configurable
49
+ * Added a VERSION constant and method (to the base class)
50
+ * Added a test suite (for those with testunit installed)
51
+ * Doc changes, rearrangement and general cleanup
52
+ * Manifest is now MANIFEST
53
+ * Added an INSTALL file
54
+
55
+ == 0.1.0 - 9-Dec-2002
56
+ * Added ping? alias for ping method
57
+ * Warnings now handled separately
58
+ * Corrected a mis-named variable in Ping::External
59
+ * Fixed the install.rb file
60
+ * Updated and added docs
61
+ * Renamed tarball to net-pingsimple to reflect RAA naming convention
62
+
63
+ == 0.0.1a
64
+ * Did this release ever happen?
65
+
66
+ == 0.0.1
67
+ * Initial release.
data/MANIFEST ADDED
@@ -0,0 +1,17 @@
1
+ MANIFEST
2
+ CHANGES
3
+ README
4
+ test.rb
5
+ install.rb
6
+
7
+ examples/test_pingexternal.rb
8
+ examples/test_pinghttp.rb
9
+ examples/test_pingtcp.rb
10
+ examples/test_pingudp.rb
11
+
12
+ net/pingsimple.rb
13
+
14
+ test/tc_pingexternal.rb
15
+ test/tc_pingtcp.rb
16
+ test/tc_pingudp.rb
17
+ test/tc_pinghttp.rb
data/README ADDED
@@ -0,0 +1,20 @@
1
+ == Description
2
+ A simple Ruby interface to the 'ping' command
3
+
4
+ == Prerequisites
5
+ * Ruby 1.8.0 or later
6
+ * The win32/open3 package is required for Win32 systems.
7
+
8
+ == Installation
9
+ === Manual Installation
10
+ ruby test.rb (optional)
11
+ ruby install.rb
12
+ === Gem Installation
13
+ ruby net-ping.gemspec
14
+ gem install net-ping-<version>.gem
15
+
16
+ == Notes
17
+ Please read the documentation. Especially pay attention to the docs
18
+ pertaining to ECONNREFUSED with regards to TCP pings.
19
+
20
+ Also note the documentation regarding down hosts.
data/doc/ping.txt ADDED
@@ -0,0 +1,205 @@
1
+ == Description
2
+ A simple Ruby interface to the 'ping' command.
3
+
4
+ == Synopsis
5
+ require "net/ping"
6
+ include Net
7
+
8
+ PingTCP.econnrefused = true
9
+
10
+ pt = Net::PingTCP.new(host)
11
+ pu = Net::PingUDP.new(host)
12
+ pe = Net::PingExternal.new(host)
13
+ ph = Net::PingHTTP.new(uri)
14
+
15
+ if pt.ping
16
+ puts "TCP ping successful"
17
+ else
18
+ puts "TCP ping unsuccessful: " + pt.exception
19
+ end
20
+
21
+ if pu.ping
22
+ puts "UDP ping successful"
23
+ else
24
+ puts "UDP ping unsuccessful: " + pu.exception
25
+ end
26
+
27
+ if pe.ping
28
+ puts "External ping successful"
29
+ else
30
+ puts "External ping unsuccessful: " + pe.exception
31
+ end
32
+
33
+ if ph.ping?
34
+ puts "HTTP ping successful"
35
+ else
36
+ puts "HTTP ping unsuccessful: " + ph.exception
37
+ end
38
+
39
+ == Ping Classes
40
+ * PingTCP
41
+ * PingUDP
42
+ * PingExternal
43
+ * PingHTTP
44
+
45
+ All Ping classes are children of the Ping parent class (which should
46
+ never be instantiated directly).
47
+
48
+ === PingTCP
49
+ PingTCP.new(host, port=7, timeout=5)
50
+ Creates and returns a new PingTCP object.
51
+
52
+ PingTCP.econnrefused
53
+ Returns the setting for how ECONNREFUSED is handled. By default, this is
54
+ set to false, i.e. an ECONNREFUSED error is considered a failed ping.
55
+
56
+ PingTCP.econnrefused=(bool)
57
+ Sets the behavior for how ECONNREFUSED is handled. By default, this is
58
+ set to false, i.e. an ECONNREFUSED error is considered a failed ping.
59
+
60
+ PingTCP#ping
61
+ PingTCP#ping?
62
+ Attempts to open a connection using TCPSocket. A successful open means
63
+ the ping was successful and true is returned. Otherwise, false is returned.
64
+
65
+ === PingUDP
66
+ PingUDP.new(host, port=7, timeout=5)
67
+ Creates and returns a new PingUDP object.
68
+
69
+ PingUDP#ping
70
+ PingUDP#ping?
71
+ Attempts to open a connection using UDPSocket and sends the value of
72
+ PingUDP#data as a string across the socket. If the return string matches,
73
+ then the ping was successful and true is returned. Otherwise, false is
74
+ returned.
75
+
76
+ PingUDP#data
77
+ Returns the string that is sent across the UDP socket.
78
+
79
+ PingUDP#data=(string)
80
+ Sets the string that is sent across the UDP socket. The default is "ping"
81
+
82
+ === PingExternal
83
+ PingExternal.new(host, port=7, timeout=5)
84
+ Creates and returns a new PingExternal object.
85
+
86
+ PingExternal#ping
87
+ PingExternal#ping?
88
+ Uses the 'open3' module and calls your system's local 'ping' command with
89
+ various options, depending on platform. If nothing is sent to stderr, the
90
+ ping was successful and true is returned. Otherwise, false is returned.
91
+
92
+ === PingHTTP
93
+ PingHTTP.new(uri, port=7, timeout=5)
94
+ Creates and returns a new PingHTTP object.
95
+
96
+ PingHTTP#ping
97
+ PingHTTP#ping?
98
+ Checks for a response against +uri+. As long as a Net::HTTPSuccess or
99
+ Net::HTTPOK response is returned, the ping is successful and true is
100
+ returned. Otherwise, false is returned and PingHTTP#exception is set to
101
+ the error message.
102
+
103
+ PingHTTP#uri
104
+ An alias for PingHTTP#host.
105
+
106
+ PingHTTP#uri=(uri)
107
+ An alias for PingHTTP#host=.
108
+
109
+ == Instance Methods
110
+ Ping#exception
111
+ Returns the error string that was set if a ping call failed. If an exception
112
+ is raised, it is caught and stored in this attribute. It is not raised in
113
+ your code.
114
+
115
+ This should be nil if the ping succeeded.
116
+
117
+ Ping#host
118
+ Returns the host name that ping attempts will ping against.
119
+
120
+ Ping#host=(hostname)
121
+ Sets the host name that ping attempts will ping against.
122
+
123
+ Ping#port
124
+ Returns the port number that ping attempts will use.
125
+
126
+ Ping#port=(port)
127
+ Set the port number to open socket connections on. The default is 7 (or
128
+ whatever your 'echo' port is set to). Note that you can also specify a
129
+ string, such as "http".
130
+
131
+ Ping#timeout
132
+ Returns the amount of time before the timeout module raises a TimeoutError
133
+ during connection attempts. The default is 5 seconds.
134
+
135
+ Ping#timeout=(time)
136
+ Sets the amount of time before the timeout module raises a TimeoutError.
137
+ during connection attempts.
138
+
139
+ Ping#warning
140
+ Returns a warning string that was returned during the ping attempt. This
141
+ typically occurs only in the PingExternal class.
142
+
143
+ == Notes
144
+ If a host is down *IT IS CONSIDERED A FAILED PING*, and the 'no answer from
145
+ +host+' text is assigned to the 'exception' attribute. You may disagree with
146
+ this behavior, in which case you need merely check the exception attribute
147
+ against a regex as a simple workaround.
148
+
149
+ == FAQ
150
+ Q: "Why don't you return exceptions if a connection fails?"
151
+
152
+ A: Because ping is only meant to return one of two things - success or
153
+ failure. It's very simple. If you want to find out *why* the ping
154
+ failed, you can check the 'exception' attribute.
155
+
156
+ Q: "I know the host is alive, but a TCP or UDP ping tells me otherwise. What
157
+ gives?"
158
+
159
+ A: It's possible that the echo port has been disabled on the remote
160
+ host for security reasons. Your best best is to specify a different port
161
+ or to use PingExternal instead.
162
+
163
+ Q: "Why does TCP ping return false when I know it should return true?"
164
+
165
+ A: By default ECONNREFUSED errors will return a value of false. This is
166
+ contrary to what most other folks do for TCP pings. The problem with
167
+ their philosphy is that you can get false positives if a firewall blocks
168
+ the route to the host. The problem with my philosophy is that you can
169
+ get false negatives if there is no firewall (or it's not blocking the
170
+ route). Given the alternatives I chose the latter.
171
+
172
+ You can always change the default behavior by using the +econnrefused+
173
+ class method.
174
+
175
+ Q: "Couldn't you use traceroute information to tell for sure?"
176
+
177
+ A: I *could* but I won't so don't bug me about it. It's far more effort than
178
+ it's worth.
179
+
180
+ == Known Bugs
181
+ You may see a test failure from the tc_pingtcp test case. You can ignore
182
+ this.
183
+
184
+ Please report any bugs on the project page at
185
+ http://www.rubyforge.org/projects/shards.
186
+
187
+ == Future Plans
188
+ Add an PingICMP class (help wanted)
189
+ (Though see arton's icmpping package on the RAA)
190
+
191
+ == License
192
+ Ruby's
193
+
194
+ == Copyright
195
+ (C) 2003-2005 Daniel J. Berger, All Rights Reserved
196
+
197
+ == Warranty
198
+ This package is provided "as is" and without any express or
199
+ implied warranties, including, without limitation, the implied
200
+ warranties of merchantability and fitness for a particular purpose.
201
+
202
+ == Author
203
+ Daniel J. Berger
204
+ djberg96 at yahoo dot com
205
+ imperator on IRC (irc.freenode.net)
data/lib/net/ping.rb ADDED
@@ -0,0 +1,229 @@
1
+ require "socket"
2
+ require "timeout"
3
+
4
+ module Net
5
+ # An abstract base class. Do not instantiate directly.
6
+ class Ping
7
+ VERSION = "1.0.0"
8
+ attr_accessor :host, :port, :timeout
9
+ attr_reader :exception, :warning
10
+
11
+ def initialize(host, port=nil, timeout=5)
12
+ @host = host
13
+ @port = port || Socket.getservbyname("echo") || 7
14
+ @timeout = timeout
15
+ @data = "ping"
16
+ @exception = nil
17
+ @warning = nil
18
+ end
19
+
20
+ def ping
21
+ @exception = nil
22
+ @warning = nil
23
+ end
24
+ end
25
+
26
+ ##########################################################################
27
+ # With a TCP ping, simply try to open a connection. If we are successful,
28
+ # assume success. In either case, close the connection to be polite.
29
+ ##########################################################################
30
+ class PingTCP < Ping
31
+ @@econnrefused = false
32
+
33
+ # Returns true if the ECONNREFUSED error is to be considered a
34
+ # successful ping. The default is false.
35
+ def self.econnrefused
36
+ @@econnrefused
37
+ end
38
+
39
+ # An alias for PingTCP.econnrefused
40
+ def self.ecr
41
+ self.econnrefused
42
+ end
43
+
44
+ # Sets whether or not an ECONNREFUSED error should be considered a
45
+ # successful ping or not.
46
+ def self.econnrefused=(bool)
47
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
48
+ raise ArgumentError, "argument must be true or false"
49
+ end
50
+ @@econnrefused = bool
51
+ end
52
+
53
+ # An alias for PingTCP.econnrefused=
54
+ def self.ecr=(bool)
55
+ self.econnrefused = bool
56
+ end
57
+
58
+ # This method attempts to ping a host and port using a TCPSocket with
59
+ # the host and port values passed to the constructor.
60
+ def ping
61
+ super
62
+ success = false
63
+ t = nil
64
+ begin
65
+ Timeout.timeout(@timeout){
66
+ begin
67
+ t = TCPSocket.new(@host,@port)
68
+ rescue Errno::ECONNREFUSED => e
69
+ if @@econnrefused == true
70
+ success = true
71
+ else
72
+ @exception = e
73
+ end
74
+ rescue Exception => e
75
+ @exception = e
76
+ else
77
+ success = true
78
+ end
79
+ }
80
+ rescue TimeoutError => t
81
+ @exception = t
82
+ ensure
83
+ t.close if t
84
+ end
85
+ success
86
+ end
87
+
88
+ alias ping? ping
89
+ end
90
+
91
+ ##########################################################################
92
+ # With a UDP ping, send a simple text string and check the return string.
93
+ # If they match, assume success.
94
+ ##########################################################################
95
+ class PingUDP < Ping
96
+ attr_accessor :data
97
+
98
+ # Sends a simple text string and checks the return string. If they
99
+ # match, the ping was successful.
100
+ def ping
101
+ super
102
+ success = false
103
+ u = UDPSocket.open
104
+ a = []
105
+ begin
106
+ Timeout.timeout(@timeout){
107
+ u.connect(@host,@port)
108
+ u.send(@data,0)
109
+ a = u.recvfrom(64)
110
+ }
111
+ rescue Exception => e
112
+ @exception = e
113
+ else
114
+ if a[0] == @data
115
+ success = true
116
+ end
117
+ ensure
118
+ u.close if u
119
+ end
120
+ success
121
+ end
122
+
123
+ alias ping? ping
124
+ end
125
+
126
+ ##################################
127
+ # Use your system's ping command
128
+ ##################################
129
+ class PingExternal < Ping
130
+
131
+ # Pings the host using your system's ping utility and checks for any
132
+ # errors or warnings.
133
+ def ping
134
+ super
135
+ input, output, error = ""
136
+ pstring = "ping "
137
+ success = false
138
+
139
+ case PLATFORM
140
+ when /linux|bsd/i
141
+ pstring += "-c 1 #{@host}"
142
+ when /solaris|sunos/i
143
+ pstring += "#{@host} 1"
144
+ when /hpux/i
145
+ pstring += "#{@host} -n 1"
146
+ when /win32|windows/i
147
+ pstring += "-n 1 #{@host}"
148
+ else
149
+ pstring += "#{@host}"
150
+ end
151
+
152
+ if File::ALT_SEPARATOR
153
+ require "win32/open3"
154
+ else
155
+ require "open3"
156
+ end
157
+
158
+ Timeout.timeout(@timeout){
159
+ input, output, error = Open3.popen3(pstring)
160
+ }
161
+
162
+ e = error.gets # Can't chomp yet, might be nil
163
+
164
+ input.close
165
+ error.close
166
+
167
+ unless e.nil?
168
+ if e =~ /warning/i
169
+ @warning = e.chomp
170
+ success = true
171
+ else
172
+ @exception = e.chomp
173
+ end
174
+ # The "no answer" response goes to stdout, not stderr, so check it
175
+ else
176
+ lines = output.readlines
177
+ output.close
178
+ if lines.nil? || lines.empty?
179
+ success = true
180
+ else
181
+ regexp = /no answer|host unreachable|could not find host/i
182
+ lines.each{ |e|
183
+ if regexp.match(e)
184
+ @exception = e.chomp
185
+ end
186
+ }
187
+ success = true
188
+ end
189
+ end
190
+ success
191
+ end
192
+
193
+ alias ping? ping
194
+ end
195
+
196
+ # For this class, +host+ is actually a URI.
197
+ class PingHTTP < Ping
198
+ require "net/http"
199
+ require "uri"
200
+ include Net
201
+
202
+ # Looks for an HTTP response from the URI passed to the constructor.
203
+ # If the result is HTTPSuccess or HTTPOK, the ping was successful.
204
+ def ping
205
+ super
206
+ success = false
207
+
208
+ begin
209
+ resp = HTTP.get_response(URI.parse(@host), nil, @timeout)
210
+ rescue Exception => e
211
+ @exception = e
212
+ else
213
+ case resp
214
+ when Net::HTTPSuccess, Net::HTTPOK
215
+ success = true
216
+ else
217
+ @exception = resp.message
218
+ end
219
+ end
220
+
221
+ success
222
+ end
223
+
224
+ alias ping? ping
225
+ alias uri host
226
+ alias uri= host=
227
+ end
228
+
229
+ end # Net
@@ -0,0 +1,62 @@
1
+ ############################################
2
+ # tc_pingexternal.rb
3
+ #
4
+ # Test case for the Net::PingExternal class
5
+ ############################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /net-pingsimple.*/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
+ end
12
+
13
+ require "test/unit"
14
+ require "net/ping"
15
+ include Net
16
+
17
+ class TC_PingExternal < Test::Unit::TestCase
18
+ def setup
19
+ @host = "www.ruby-lang.org"
20
+ @bogus = "foo.bar.baz"
21
+ @pe = PingExternal.new(@host)
22
+ @bad = PingExternal.new(@bogus)
23
+ end
24
+
25
+ def test_version
26
+ assert_equal("1.0.0", PingExternal::VERSION, "Bad version constant")
27
+ end
28
+
29
+ def test_ping
30
+ assert_respond_to(@pe, :ping)
31
+ assert_respond_to(@pe, :ping?)
32
+ assert_nothing_raised{ @pe.ping }
33
+ assert_raises(ArgumentError){ @pe.ping(@host) }
34
+ end
35
+
36
+ def test_good_ping
37
+ assert_equal(true, @pe.ping?)
38
+ end
39
+
40
+ def test_bad_ping
41
+ assert_equal(false, @bad.ping?)
42
+ assert_equal(false, @bad.exception.nil?, "Bad exception data")
43
+ end
44
+
45
+ def test_accessors
46
+ assert_respond_to(@pe, :host)
47
+ assert_respond_to(@pe, :host=)
48
+ assert_respond_to(@pe, :port)
49
+ assert_respond_to(@pe, :port=)
50
+ assert_respond_to(@pe, :timeout)
51
+ assert_respond_to(@pe, :timeout=)
52
+ assert_respond_to(@pe, :exception)
53
+ assert_respond_to(@pe, :warning)
54
+ end
55
+
56
+ def teardown
57
+ @host = nil
58
+ @bogus = nil
59
+ @pe = nil
60
+ @bad = nil
61
+ end
62
+ end
@@ -0,0 +1,58 @@
1
+ #########################################
2
+ # tc_pinghttp.rb
3
+ #
4
+ # Test case for the Net::PingHTTP class.
5
+ #########################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /net-pingsimple.*/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
+ end
12
+
13
+ require "test/unit"
14
+ require "net/ping"
15
+ include Net
16
+
17
+ class TC_PingHTTP < Test::Unit::TestCase
18
+ def setup
19
+ @uri = "http://www.pragmaticprogrammer.com/index.html"
20
+ @http = PingHTTP.new(@uri)
21
+ @bad = PingHTTP.new("http://www.blabfoobarurgh.com")
22
+ end
23
+
24
+ def test_version
25
+ assert_equal("1.0.0", PingHTTP::VERSION, "Bad version constant")
26
+ end
27
+
28
+ def test_ping
29
+ assert_respond_to(@http, :ping)
30
+ assert_respond_to(@http, :ping?)
31
+ assert_nothing_raised{ @http.ping }
32
+ assert_raises(ArgumentError){ @http.ping(@host) }
33
+ end
34
+
35
+ def test_ping_success
36
+ assert_equal(true, @http.ping?)
37
+ assert_equal(false, @bad.ping?)
38
+ assert_not_nil(@bad.exception)
39
+ end
40
+
41
+ def test_accessors
42
+ assert_respond_to(@http, :host)
43
+ assert_respond_to(@http, :host=)
44
+ assert_respond_to(@http, :port)
45
+ assert_respond_to(@http, :port=)
46
+ assert_respond_to(@http, :timeout)
47
+ assert_respond_to(@http, :timeout=)
48
+ assert_respond_to(@http, :exception)
49
+ assert_respond_to(@http, :warning)
50
+ assert_respond_to(@http, :uri)
51
+ assert_respond_to(@http, :uri=)
52
+ end
53
+
54
+ def teardown
55
+ @uri = nil
56
+ @http = nil
57
+ end
58
+ end
@@ -0,0 +1,69 @@
1
+ #######################################
2
+ # tc_pingtcp.rb
3
+ #
4
+ # Test case for the Net::PingTCP class
5
+ #######################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /net-pingsimple.*/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
+ end
12
+
13
+ require "test/unit"
14
+ require "net/ping"
15
+ include Net
16
+
17
+ class TC_PingTCP < Test::Unit::TestCase
18
+ def setup
19
+ @host = "www.ruby-lang.org"
20
+ @tcp = PingTCP.new(@host, "http")
21
+ end
22
+
23
+ def test_version
24
+ assert_equal("1.0.0", PingTCP::VERSION, "Bad version constant")
25
+ end
26
+
27
+ def test_ping
28
+ assert_respond_to(@tcp, :ping)
29
+ assert_respond_to(@tcp, :ping?)
30
+ assert_nothing_raised{ @tcp.ping }
31
+ assert_raises(ArgumentError){ @tcp.ping(@host) }
32
+ end
33
+
34
+ def test_ping_ecr_false
35
+ PingTCP.ecr = false
36
+ assert_equal(false, @tcp.ping?)
37
+ assert_equal(false, @tcp.exception.nil?, "Bad exception data")
38
+ end
39
+
40
+ def test_ping_ecr_true
41
+ msg = "+this test may fail depending on your network environment+"
42
+ PingTCP.ecr = true
43
+ assert_equal(true, @tcp.ping?, msg)
44
+ end
45
+
46
+ def test_ecr
47
+ assert_respond_to(PingTCP, :econnrefused)
48
+ assert_respond_to(PingTCP, :econnrefused=)
49
+ assert_respond_to(PingTCP, :ecr)
50
+ assert_respond_to(PingTCP, :ecr=)
51
+ assert_raises(ArgumentError){ PingTCP.ecr = "blah" }
52
+ end
53
+
54
+ def test_accessors
55
+ assert_respond_to(@tcp, :host)
56
+ assert_respond_to(@tcp, :host=)
57
+ assert_respond_to(@tcp, :port)
58
+ assert_respond_to(@tcp, :port=)
59
+ assert_respond_to(@tcp, :timeout)
60
+ assert_respond_to(@tcp, :timeout=)
61
+ assert_respond_to(@tcp, :exception)
62
+ assert_respond_to(@tcp, :warning)
63
+ end
64
+
65
+ def teardown
66
+ @host = nil
67
+ @tcp = nil
68
+ end
69
+ end
@@ -0,0 +1,59 @@
1
+ ################################################################
2
+ # tc_pingudp.rb
3
+ #
4
+ # Test case for the Net::PingUDP class
5
+ #
6
+ # If someone could provide me a host where a udp ping actually
7
+ # works, I would appreciate it. :)
8
+ ################################################################
9
+ base = File.basename(Dir.pwd)
10
+
11
+ if base == "test" || base =~ /net-pingsimple.*/
12
+ Dir.chdir("..") if base == "test"
13
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
14
+ end
15
+
16
+ require "test/unit"
17
+ require "net/ping"
18
+ include Net
19
+
20
+ class TC_PingUDP < Test::Unit::TestCase
21
+ def setup
22
+ @host = "www.ruby-lang.org"
23
+ @udp = PingUDP.new(@host)
24
+ end
25
+
26
+ def test_version
27
+ assert_equal("1.0.0", PingUDP::VERSION, "Bad version constant")
28
+ end
29
+
30
+ def test_ping
31
+ assert_respond_to(@udp, :ping)
32
+ assert_respond_to(@udp, :ping?)
33
+ assert_nothing_raised{ @udp.ping }
34
+ assert_raises(ArgumentError){ @udp.ping(@host) }
35
+ end
36
+
37
+ def test_ping_standard
38
+ assert_equal(false, @udp.ping?)
39
+ assert_equal(false, @udp.exception.nil?, "Bad exception data")
40
+ end
41
+
42
+ def test_accessors
43
+ assert_respond_to(@udp, :host)
44
+ assert_respond_to(@udp, :host=)
45
+ assert_respond_to(@udp, :port)
46
+ assert_respond_to(@udp, :port=)
47
+ assert_respond_to(@udp, :timeout)
48
+ assert_respond_to(@udp, :timeout=)
49
+ assert_respond_to(@udp, :data)
50
+ assert_respond_to(@udp, :data=)
51
+ assert_respond_to(@udp, :exception)
52
+ assert_respond_to(@udp, :warning)
53
+ end
54
+
55
+ def teardown
56
+ @host = nil
57
+ @udp = nil
58
+ end
59
+ end
data/test/ts_ping.rb ADDED
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(Dir.pwd)
2
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
3
+ $LOAD_PATH.unshift(Dir.pwd + "/test")
4
+
5
+ require "tc_pingexternal"
6
+ require "tc_pinghttp"
7
+ require "tc_pingtcp"
8
+ require "tc_pingudp"
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.10
3
+ specification_version: 1
4
+ name: net-ping
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2005-06-14
8
+ summary: A ping interface for Ruby
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/shards
13
+ rubyforge_project:
14
+ description: A ping interface for Ruby
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ authors:
27
+ - Daniel J. Berger
28
+ files:
29
+ - lib/net/ping.rb
30
+ - CHANGES
31
+ - MANIFEST
32
+ - README
33
+ - test/tc_pingexternal.rb
34
+ - test/tc_pinghttp.rb
35
+ - test/tc_pingtcp.rb
36
+ - test/tc_pingudp.rb
37
+ - test/ts_ping.rb
38
+ - doc/ping.txt
39
+ test_files:
40
+ - test/ts_ping.rb
41
+ rdoc_options: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ - CHANGES
46
+ - doc/ping.txt
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ requirements: []
52
+
53
+ dependencies: []
54
+