net-ping 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,21 @@
1
+ == 1.2.2 - 22-Jan-2008
2
+ * Bug fix for Ping::External where it was not honoring the timeout value.
3
+ Thanks go to Chris Morris for the spot and the patch.
4
+ * Bug fix for Ping::External where non-English output could cause false
5
+ positives on MS Windows Vista or later. This library now requires the
6
+ windows-pr library on MS Windows systems as a result.
7
+ * Added the Ping::UDP.service_check and Ping::UDP.service_check= class
8
+ methods. This method controls whether or not Errno::ECONNREFUSED or
9
+ Errno::ECONNRESET are considered successful pings or not.
10
+ * The Ping::HTTP class no longer uses the resolv-replace library on MS Windows
11
+ because it was (ironically) causing timeouts.
12
+ * Changed the Ping::TCP.econnrefused method to Ping::TCP.service_check. I
13
+ changed it because I now use a similar method in Ping::UDP, but that handles
14
+ more than Errno::ECONNREFUSED. An alias is provided to provide backwards
15
+ compatibility, but it is considered deprecated and will be removed in the
16
+ 1.3.0 release.
17
+ * Removed the install.rb file. The Rakefile now handles installation.
18
+
1
19
  == 1.2.1 - 6-Apr-2007
2
20
  * For the Ping::External class, if a ping attempt results in 100% packet loss
3
21
  it is now considered a failed ping, regardless of whether or not an error
data/MANIFEST CHANGED
@@ -2,8 +2,6 @@
2
2
  * CHANGES
3
3
  * Rakefile
4
4
  * README
5
- * test.rb
6
- * install.rb
7
5
  * net-ping.gemspec
8
6
  * examples/test_pingexternal.rb
9
7
  * examples/test_pinghttp.rb
data/README CHANGED
@@ -1,18 +1,18 @@
1
1
  == Description
2
- A simple Ruby interface to the 'ping' command
2
+ A collection of classes that provide different ways to ping computers.
3
3
 
4
4
  == Prerequisites
5
5
  * Ruby 1.8.0 or later
6
- * The win32/open3 package is required for Win32 systems when using the
7
- Net::Ping::External class.
6
+ * The win32-open3 and windows-pr libraries are required on MS Windows
7
+ when using the Net::Ping::External class.
8
8
 
9
9
  == Installation
10
10
  rake test (optional)
11
11
  rake install (standard) OR rake gem_install (gems)
12
12
 
13
13
  == Notes
14
- Please read the documentation. Especially pay attention to the docs
15
- pertaining to ECONNREFUSED with regards to TCP pings.
14
+ Please read the documentation under the 'doc' directory. Especially pay
15
+ attention to the documentation pertaining to ECONNREFUSED and TCP pings.
16
16
 
17
17
  Also note the documentation regarding down hosts.
18
18
 
@@ -21,11 +21,11 @@
21
21
 
22
22
  require 'net/ping'
23
23
 
24
- In which case you will get Net::Ping and all of its subclasses. Or,
24
+ In which case you will get Net::Ping and all of its subclasses. Or,
25
25
  you can load individual subclasses like this:
26
26
 
27
27
  require 'net/ping/tcp'
28
28
 
29
29
  The former has the advantage of being easier to remember and all inclusive,
30
- not to mention backwards compatible. The latter has the advantage of
30
+ not to mention backwards compatible. The latter has the advantage of
31
31
  reducing your memory footprint.
data/Rakefile CHANGED
@@ -1,9 +1,20 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ include Config
3
4
 
4
- desc "Install the net-ping package without gems"
5
+ desc "Install the net-ping package (non-gem)"
5
6
  task :install do
6
- ruby 'install.rb'
7
+ dest1 = File.join(CONFIG['sitelibdir'], 'net')
8
+ dest2 = File.join(dest1, 'ping')
9
+
10
+ Dir.mkdir(dest1) unless File.exists?(dest1)
11
+ Dir.mkdir(dest2) unless File.exists?(dest2)
12
+
13
+ FileUtils.cp('lib/net/ping.rb', dest1, :verbose => true)
14
+
15
+ Dir['lib/net/ping/*.rb'].each{ |file|
16
+ FileUtils.cp(file, dest2, :verbose => true)
17
+ }
7
18
  end
8
19
 
9
20
  desc "Create and install a net-ping gem"
@@ -54,12 +54,12 @@ Net::Ping.new(host=nil, port=7, timeout=5)
54
54
  in the constructor then it must be specified in the ping method.
55
55
 
56
56
  == Net::Ping::TCP
57
- Ping::TCP.econnrefused
58
- Returns the setting for how ECONNREFUSED is handled. By default, this is
57
+ Ping::TCP.service_check
58
+ Returns the setting for how ECONNREFUSED is handled. By default, this is
59
59
  set to false, i.e. an ECONNREFUSED error is considered a failed ping.
60
60
 
61
- Ping::TCP.econnrefused=(bool)
62
- Sets the behavior for how ECONNREFUSED is handled. By default, this is
61
+ Ping::TCP.service_check=(bool)
62
+ Sets the behavior for how ECONNREFUSED is handled. By default, this is
63
63
  set to false, i.e. an ECONNREFUSED error is considered a failed ping.
64
64
 
65
65
  Ping::TCP#ping(host=nil)
@@ -166,35 +166,41 @@ Ping#warning
166
166
  Q: "Why don't you return exceptions if a connection fails?"
167
167
 
168
168
  A: Because ping is only meant to return one of two things - success or
169
- failure. It's very simple. If you want to find out *why* the ping
169
+ failure. It's very simple. If you want to find out *why* the ping
170
170
  failed, you can check the 'exception' attribute.
171
171
 
172
172
  Q: "I know the host is alive, but a TCP or UDP ping tells me otherwise. What
173
173
  gives?"
174
174
 
175
175
  A: It's possible that the echo port has been disabled on the remote
176
- host for security reasons. Your best best is to specify a different port
176
+ host for security reasons. Your best best is to specify a different port
177
177
  or to use Ping::ICMP or Ping::External instead.
178
+
179
+ In the case of UDP pings, they are often actively refused. It may be
180
+ more pragmatic to set Ping::UDP.service_check = false.
178
181
 
179
- Q: "Why does TCP ping return false when I know it should return true?"
182
+ Q: "Why does a TCP ping return false when I know it should return true?"
180
183
 
181
- A: By default ECONNREFUSED errors will return a value of false. This is
182
- contrary to what most other folks do for TCP pings. The problem with
183
- their philosphy is that you can get false positives if a firewall blocks
184
- the route to the host. The problem with my philosophy is that you can
184
+ A: By default ECONNREFUSED errors will return a value of false. This is
185
+ contrary to what most other folks do for TCP pings. The problem with
186
+ their philosophy is that you can get false positives if a firewall blocks
187
+ the route to the host. The problem with my philosophy is that you can
185
188
  get false negatives if there is no firewall (or it's not blocking the
186
- route). Given the alternatives I chose the latter.
189
+ route). Given the alternatives I chose the latter.
187
190
 
188
- You can always change the default behavior by using the +econnrefused+
191
+ You can always change the default behavior by using the +service_check+
189
192
  class method.
193
+
194
+ A similar situation is true for UDP pings.
190
195
 
191
196
  Q: "Couldn't you use traceroute information to tell for sure?"
192
197
 
193
- A: I *could* but I won't so don't bug me about it. It's far more effort than
194
- it's worth.
198
+ A: I could but I won't so don't bug me about it. It's far more effort than
199
+ it's worth. If you want something like that, please port the
200
+ Net::Traceroute Perl module by Daniel Hagerty.
195
201
 
196
202
  = Known Bugs
197
- You may see a test failure from the tc_pingtcp test case. You can ignore
203
+ You may see a test failure from the tc_pingtcp test case. You can ignore
198
204
  this.
199
205
 
200
206
  Please report any bugs on the project page at
@@ -202,17 +208,17 @@ Ping#warning
202
208
 
203
209
  = Acknowledgements
204
210
  The Ping::ICMP#ping method is based largely on the identical method from
205
- the Net::Ping Perl module by Rob Brown. Much of the code was ported by
211
+ the Net::Ping Perl module by Rob Brown. Much of the code was ported by
206
212
  Jos Backus on ruby-talk.
207
213
 
208
214
  = Future Plans
209
- Add a bind method.
215
+ Add support for syn pings.
210
216
 
211
217
  = License
212
218
  Ruby's
213
219
 
214
220
  = Copyright
215
- (C) 2003-2006 Daniel J. Berger, All Rights Reserved
221
+ (C) 2003-2008 Daniel J. Berger, All Rights Reserved
216
222
 
217
223
  = Warranty
218
224
  This package is provided "as is" and without any express or
@@ -1,6 +1,14 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
  require 'ping'
3
3
 
4
+ if RUBY_PLATFORM.match('mswin')
5
+ require 'win32/open3'
6
+ require 'windows/console'
7
+ include Windows::Console
8
+ else
9
+ require 'open3'
10
+ end
11
+
4
12
  module Net
5
13
  class Ping::External < Ping
6
14
 
@@ -13,9 +21,11 @@ module Net
13
21
  #
14
22
  def ping(host = @host)
15
23
  super(host)
24
+
16
25
  input, output, error = ""
17
26
  pstring = "ping "
18
- bool = false
27
+ bool = false
28
+ orig_cp = nil
19
29
 
20
30
  case RUBY_PLATFORM
21
31
  when /linux|bsd|osx|mach|darwin/i
@@ -25,57 +35,61 @@ module Net
25
35
  when /hpux/i
26
36
  pstring += "#{host} -n 1"
27
37
  when /win32|windows|mswin/i
38
+ orig_cp = GetConsoleCP()
39
+ SetConsoleCP(437) if orig_cp != 437 # United States
28
40
  pstring += "-n 1 #{host}"
29
41
  else
30
42
  pstring += "#{host}"
31
43
  end
32
44
 
33
- if RUBY_PLATFORM.match('mswin')
34
- require 'win32/open3'
35
- else
36
- require 'open3'
37
- end
38
-
39
45
  start_time = Time.now
40
46
 
41
- Timeout.timeout(@timeout){
42
- input, output, error = Open3.popen3(pstring)
43
- }
47
+ begin
48
+ e = nil
49
+ Timeout.timeout(@timeout){
50
+ input, output, error = Open3.popen3(pstring)
51
+ e = error.gets # Can't chomp yet, might be nil
52
+ }
44
53
 
45
- e = error.gets # Can't chomp yet, might be nil
54
+ input.close
55
+ error.close
46
56
 
47
- input.close
48
- error.close
57
+ if RUBY_PLATFORM.match('mswin') && GetConsoleCP() != orig_cp
58
+ SetConsoleCP(orig_cp)
59
+ end
49
60
 
50
- unless e.nil?
51
- if e =~ /warning/i
52
- @warning = e.chomp
53
- bool = true
54
- else
55
- @exception = e.chomp
56
- end
57
- # The "no answer" response goes to stdout, not stderr, so check it
58
- else
59
- lines = output.readlines
60
- output.close
61
- if lines.nil? || lines.empty?
62
- bool = true
63
- else
64
- regexp = /
65
- no\ answer|
66
- host\ unreachable|
67
- could\ not\ find\ host|
68
- request\ timed\ out|
69
- 100%\ packet\ loss
70
- /ix
71
- lines.each{ |e|
72
- if regexp.match(e)
73
- @exception = e.chomp
74
- break
75
- end
76
- }
77
- bool = true unless @exception
78
- end
61
+ unless e.nil?
62
+ if e =~ /warning/i
63
+ @warning = e.chomp
64
+ bool = true
65
+ else
66
+ @exception = e.chomp
67
+ end
68
+ # The "no answer" response goes to stdout, not stderr, so check it
69
+ else
70
+ lines = output.readlines
71
+ output.close
72
+ if lines.nil? || lines.empty?
73
+ bool = true
74
+ else
75
+ regexp = /
76
+ no\ answer|
77
+ host\ unreachable|
78
+ could\ not\ find\ host|
79
+ request\ timed\ out|
80
+ 100%\ packet\ loss
81
+ /ix
82
+ lines.each{ |e|
83
+ if regexp.match(e)
84
+ @exception = e.chomp
85
+ break
86
+ end
87
+ }
88
+ bool = true unless @exception
89
+ end
90
+ end
91
+ rescue Exception => err
92
+ @exception = err.message
79
93
  end
80
94
 
81
95
  # There is no duration if the ping failed
@@ -1,9 +1,14 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
  require 'ping'
3
3
  require 'net/http'
4
- require 'resolv-replace' # Force non-blocking Socket.getaddrinfo
5
4
  require 'uri'
6
5
 
6
+ # Force non-blocking Socket.getaddrinfo on Unix systems. Do not use on
7
+ # Windows because it causes problems.
8
+ unless RUBY_PLATFORM.match('mswin')
9
+ require 'resolv-replace'
10
+ end
11
+
7
12
  module Net
8
13
  class Ping::HTTP < Ping
9
14
 
@@ -3,7 +3,7 @@ require 'timeout'
3
3
 
4
4
  module Net
5
5
  class Ping
6
- VERSION = '1.2.1'
6
+ VERSION = '1.2.2'
7
7
 
8
8
  # The host to ping. In the case of Ping::HTTP, this is the URI.
9
9
  attr_accessor :host
@@ -3,36 +3,36 @@ require 'ping'
3
3
 
4
4
  module Net
5
5
 
6
- # With a TCP ping, simply try to open a connection. If we are boolful,
6
+ # With a TCP ping, simply try to open a connection. If we are successful,
7
7
  # assume bool. In either case, close the connection to be polite.
8
8
  #
9
9
  class Ping::TCP < Ping
10
- @@econnrefused = false
10
+ @@service_check = false
11
11
 
12
- # Returns whether or not Errno::ECONNREFUSED is considered a boolful
13
- # ping. The default is false.
12
+ # Returns whether or not Errno::ECONNREFUSED is considered a successful
13
+ # ping. The default is false.
14
14
  #
15
- def self.econnrefused
16
- @@econnrefused
15
+ def self.service_check
16
+ @@service_check
17
17
  end
18
18
 
19
19
  # Sets whether or not an Errno::ECONNREFUSED should be considered a
20
- # boolful ping.
20
+ # successful ping.
21
21
  #
22
- def self.econnrefused=(bool)
22
+ def self.service_check=(bool)
23
23
  unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
24
24
  raise ArgumentError, 'argument must be true or false'
25
25
  end
26
- @@econnrefused = bool
26
+ @@service_check = bool
27
27
  end
28
28
 
29
29
  # This method attempts to ping a host and port using a TCPSocket with
30
30
  # the host, port and timeout values passed in the constructor. Returns
31
- # true if boolful, or false otherwise.
31
+ # true if successful, or false otherwise.
32
32
  #
33
33
  # Note that, by default, an Errno::ECONNREFUSED return result will be
34
34
  # considered a failed ping. See the documentation for the
35
- # Ping::TCP.econnrefused= method if you wish to change this behavior.
35
+ # Ping::TCP.service_check= method if you wish to change this behavior.
36
36
  #
37
37
  def ping(host=@host)
38
38
  super(host)
@@ -46,7 +46,7 @@ module Net
46
46
  begin
47
47
  tcp = TCPSocket.new(host, @port)
48
48
  rescue Errno::ECONNREFUSED => err
49
- if @@econnrefused
49
+ if @@service_check
50
50
  bool = true
51
51
  else
52
52
  @exception = err
@@ -72,10 +72,12 @@ module Net
72
72
  alias ping? ping
73
73
  alias pingecho ping
74
74
 
75
- # Class method aliases
75
+ # Class method aliases. DEPRECATED.
76
76
  class << self
77
- alias ecr econnrefused
78
- alias ecr= econnrefused=
77
+ alias econnrefused service_check
78
+ alias econnrefused= service_check=
79
+ alias ecr service_check
80
+ alias ecr= service_check=
79
81
  end
80
82
  end
81
83
 
@@ -3,6 +3,29 @@ require 'ping'
3
3
 
4
4
  module Net
5
5
  class Ping::UDP < Ping
6
+ @@service_check = true
7
+
8
+ # Returns whether or not the connect behavior should enforce remote
9
+ # service availability as well as reachability. The default is true.
10
+ #
11
+ def self.service_check
12
+ @@service_check
13
+ end
14
+
15
+ # Set whether or not the connect behavior should enforce remote
16
+ # service availability as well as reachability. If set to false
17
+ # then Errno::ECONNREFUSED or Errno::ECONNRESET will be considered
18
+ # a successful ping, meaning no actual data handshaking is required.
19
+ # By default, if either of those errors occurs it is considered a failed
20
+ # ping.
21
+ #
22
+ def self.service_check=(bool)
23
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
24
+ raise ArgumentError, 'argument must be true or false'
25
+ end
26
+ @@service_check = bool
27
+ end
28
+
6
29
  MAX_DATA = 64
7
30
 
8
31
  # The data to send to the remote host. By default this is 'ping'.
@@ -65,6 +88,12 @@ module Net
65
88
  udp.send(@data, 0)
66
89
  array = udp.recvfrom(MAX_DATA)
67
90
  }
91
+ rescue Errno::ECONNREFUSED, Errno::ECONNRESET => err
92
+ if @@service_check
93
+ @exception = err
94
+ else
95
+ bool = true
96
+ end
68
97
  rescue Exception => err
69
98
  @exception = err
70
99
  else
@@ -4,20 +4,20 @@
4
4
  # Test case for the Net::PingExternal class. Run this via the 'test' or
5
5
  # 'test_external' rake task.
6
6
  #########################################################################
7
- require "test/unit"
8
- require "net/ping/external"
7
+ require 'test/unit'
8
+ require 'net/ping/external'
9
9
  include Net
10
10
 
11
11
  class TC_PingExternal < Test::Unit::TestCase
12
12
  def setup
13
- @host = "www.ruby-lang.org"
14
- @bogus = "foo.bar.baz"
13
+ @host = 'www.ruby-lang.org'
14
+ @bogus = 'foo.bar.baz'
15
15
  @pe = Ping::External.new(@host)
16
16
  @bad = Ping::External.new(@bogus)
17
17
  end
18
18
 
19
19
  def test_version
20
- assert_equal("1.2.1", PingExternal::VERSION)
20
+ assert_equal('1.2.2', PingExternal::VERSION)
21
21
  end
22
22
 
23
23
  def test_ping
@@ -4,19 +4,19 @@
4
4
  # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
5
  # 'test_http' test task.
6
6
  #################################################################################
7
- require "test/unit"
8
- require "net/ping/http"
7
+ require 'test/unit'
8
+ require 'net/ping/http'
9
9
  include Net
10
10
 
11
11
  class TC_PingHTTP < Test::Unit::TestCase
12
12
  def setup
13
- @uri = "http://www.pragmaticprogrammer.com/index.html"
13
+ @uri = 'http://www.google.com/index.html'
14
14
  @http = Ping::HTTP.new(@uri, 80, 30)
15
- @bad = Ping::HTTP.new("http://www.blabfoobarurgh.com") # One hopes not
15
+ @bad = Ping::HTTP.new('http://www.blabfoobarurgh.com') # One hopes not
16
16
  end
17
17
 
18
18
  def test_version
19
- assert_equal("1.2.1", Ping::HTTP::VERSION)
19
+ assert_equal('1.2.2', Ping::HTTP::VERSION)
20
20
  end
21
21
 
22
22
  def test_ping
@@ -48,7 +48,7 @@ class TC_PingHTTP < Test::Unit::TestCase
48
48
  assert_respond_to(@http, :host=)
49
49
  assert_respond_to(@http, :uri) # Alias
50
50
  assert_respond_to(@http, :uri=) # Alias
51
- assert_equal('http://www.pragmaticprogrammer.com/index.html', @http.host)
51
+ assert_equal('http://www.google.com/index.html', @http.host)
52
52
  end
53
53
 
54
54
  def test_port
@@ -5,8 +5,8 @@
5
5
  # with root privileges on UNIX systems. This should be run via the
6
6
  # 'test' or 'test_icmp' Rake task.
7
7
  #######################################################################
8
- require "test/unit"
9
- require "net/ping/icmp"
8
+ require 'test/unit'
9
+ require 'net/ping/icmp'
10
10
  include Net
11
11
 
12
12
  unless Process.euid == 0
@@ -20,7 +20,7 @@ class TC_PingICMP < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  def test_version
23
- assert_equal("1.2.1", PingICMP::VERSION)
23
+ assert_equal('1.2.2', PingICMP::VERSION)
24
24
  end
25
25
 
26
26
  def test_ping
@@ -4,18 +4,18 @@
4
4
  # Test case for the Net::PingTCP class. This test should be run via
5
5
  # the 'test' or 'test_tcp' Rake task.
6
6
  #####################################################################
7
- require "test/unit"
8
- require "net/ping/tcp"
7
+ require 'test/unit'
8
+ require 'net/ping/tcp'
9
9
  include Net
10
10
 
11
11
  class TC_PingTCP < Test::Unit::TestCase
12
12
  def setup
13
- @host = "www.ruby-lang.org"
13
+ @host = Socket.gethostname
14
14
  @tcp = Ping::TCP.new(@host)
15
15
  end
16
16
 
17
17
  def test_version
18
- assert_equal("1.2.1", PingTCP::VERSION)
18
+ assert_equal('1.2.2', PingTCP::VERSION)
19
19
  end
20
20
 
21
21
  def test_ping
@@ -33,25 +33,34 @@ class TC_PingTCP < Test::Unit::TestCase
33
33
  assert_nothing_raised{ @tcp.pingecho(@host) }
34
34
  end
35
35
 
36
- def test_ping_ecr_false
36
+ def test_ping_service_check_false
37
37
  msg = "+this test may fail depending on your network environment+"
38
- PingTCP.ecr = false
38
+ PingTCP.service_check = false
39
39
  assert_equal(false, @tcp.ping?, msg)
40
40
  assert_equal(false, @tcp.exception.nil?, "Bad exception data")
41
41
  end
42
42
 
43
- def test_ping_ecr_true
43
+ def test_ping_service_check_true
44
44
  msg = "+this test may fail depending on your network environment+"
45
- PingTCP.ecr = true
45
+ PingTCP.service_check = true
46
46
  assert_equal(true, @tcp.ping?, msg)
47
47
  end
48
48
 
49
- def test_ecr
49
+ def test_service_check
50
+ assert_respond_to(PingTCP, :service_check)
51
+ assert_respond_to(PingTCP, :service_check=)
52
+ end
53
+
54
+ # These will be removed in 1.3.0
55
+ def test_service_check_aliases
50
56
  assert_respond_to(PingTCP, :econnrefused)
51
57
  assert_respond_to(PingTCP, :econnrefused=)
52
58
  assert_respond_to(PingTCP, :ecr)
53
- assert_respond_to(PingTCP, :ecr=)
54
- assert_raises(ArgumentError){ PingTCP.ecr = "blah" }
59
+ assert_respond_to(PingTCP, :ecr=)
60
+ end
61
+
62
+ def test_service_check_expected_errors
63
+ assert_raises(ArgumentError){ PingTCP.service_check = "blah" }
55
64
  end
56
65
 
57
66
  def test_duration
@@ -63,7 +72,7 @@ class TC_PingTCP < Test::Unit::TestCase
63
72
  def test_host
64
73
  assert_respond_to(@tcp, :host)
65
74
  assert_respond_to(@tcp, :host=)
66
- assert_equal('www.ruby-lang.org', @tcp.host)
75
+ assert_equal(@host, @tcp.host)
67
76
  end
68
77
 
69
78
  def test_port
@@ -5,20 +5,21 @@
5
5
  # via the 'test' or 'test_udp' Rake task.
6
6
  #
7
7
  # If someone could provide me a host where a udp ping actually
8
- # works, I would appreciate it. :)
8
+ # works (with a service check), I would appreciate it. :)
9
9
  ################################################################
10
- require "test/unit"
11
- require "net/ping/udp"
10
+ require 'test/unit'
11
+ require 'net/ping/udp'
12
12
  include Net
13
13
 
14
14
  class TC_PingUDP < Test::Unit::TestCase
15
15
  def setup
16
- @host = "www.ruby-lang.org"
16
+ Ping::UDP.service_check = false
17
+ @host = '127.0.0.1'
17
18
  @udp = Ping::UDP.new(@host)
18
19
  end
19
20
 
20
21
  def test_version
21
- assert_equal("1.2.1", Ping::UDP::VERSION)
22
+ assert_equal('1.2.2', Ping::UDP::VERSION)
22
23
  end
23
24
 
24
25
  def test_ping
@@ -37,13 +38,13 @@ class TC_PingUDP < Test::Unit::TestCase
37
38
  end
38
39
 
39
40
  def test_ping_standard
40
- assert_equal(false, @udp.ping?)
41
- assert_equal(false, @udp.exception.nil?, "Bad exception data")
41
+ assert_equal(true, @udp.ping?)
42
+ assert_equal(true, @udp.exception.nil?)
42
43
  end
43
44
 
44
45
  def test_bind
45
46
  assert_respond_to(@udp, :bind)
46
- assert_nothing_raised{ @udp.bind('www.ruby-lang.org', 80) }
47
+ assert_nothing_raised{ @udp.bind('127.0.0.1', 80) }
47
48
  end
48
49
 
49
50
  def test_duration
@@ -55,7 +56,7 @@ class TC_PingUDP < Test::Unit::TestCase
55
56
  def test_host
56
57
  assert_respond_to(@udp, :host)
57
58
  assert_respond_to(@udp, :host=)
58
- assert_equal('www.ruby-lang.org', @udp.host)
59
+ assert_equal('127.0.0.1', @udp.host)
59
60
  end
60
61
 
61
62
  def test_port
@@ -79,6 +80,17 @@ class TC_PingUDP < Test::Unit::TestCase
79
80
  def test_warning
80
81
  assert_respond_to(@udp, :warning)
81
82
  end
83
+
84
+ def test_service_check
85
+ assert_respond_to(Ping::UDP, :service_check)
86
+ assert_respond_to(Ping::UDP, :service_check=)
87
+ assert_equal(false, Ping::UDP.service_check) # Set in setup
88
+ end
89
+
90
+ def test_service_check_expected_failures
91
+ assert_raise(ArgumentError){ Ping::UDP.service_check(1) }
92
+ assert_raise(ArgumentError){ Ping::UDP.service_check = 1 }
93
+ end
82
94
 
83
95
  def teardown
84
96
  @host = nil
metadata CHANGED
@@ -1,46 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: net-ping
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.2.1
7
- date: 2007-04-06 00:00:00 -06:00
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. Includes TCP, HTTP, ICMP, UDP, and External ping interfaces.
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:
4
+ version: 1.2.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A ping interface for Ruby. Includes TCP, HTTP, ICMP, UDP, and External ping interfaces.
17
+ email: djberg96@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - CHANGES
25
+ - doc/ping.txt
31
26
  files:
27
+ - lib/net/CVS
32
28
  - lib/net/ping
33
29
  - lib/net/ping.rb
34
30
  - CHANGES
31
+ - CVS
35
32
  - MANIFEST
36
- - README
37
33
  - Rakefile
34
+ - README
35
+ - test/CVS
38
36
  - test/tc_pingexternal.rb
39
37
  - test/tc_pinghttp.rb
40
38
  - test/tc_pingicmp.rb
41
39
  - test/tc_pingtcp.rb
42
40
  - test/tc_pingudp.rb
43
41
  - test/ts_ping.rb
42
+ - lib/net/ping/CVS
44
43
  - lib/net/ping/external.rb
45
44
  - lib/net/ping/http.rb
46
45
  - lib/net/ping/icmp.rb
@@ -48,19 +47,31 @@ files:
48
47
  - lib/net/ping/tcp.rb
49
48
  - lib/net/ping/udp.rb
50
49
  - doc/ping.txt
51
- test_files:
52
- - test/ts_ping.rb
50
+ has_rdoc: true
51
+ homepage: http://www.rubyforge.org/projects/shards
52
+ post_install_message:
53
53
  rdoc_options: []
54
54
 
55
- extra_rdoc_files:
56
- - README
57
- - CHANGES
58
- - doc/ping.txt
59
- executables: []
60
-
61
- extensions: []
62
-
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
63
69
  requirements: []
64
70
 
65
- dependencies: []
66
-
71
+ rubyforge_project: shards
72
+ rubygems_version: 1.0.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: A ping interface for Ruby.
76
+ test_files:
77
+ - test/ts_ping.rb