net-ping 1.3.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +189 -0
- data/MANIFEST +23 -0
- data/README +48 -0
- data/Rakefile +84 -0
- data/doc/ping.txt +249 -0
- data/examples/example_pingexternal.rb +16 -0
- data/examples/example_pinghttp.rb +22 -0
- data/examples/example_pingtcp.rb +16 -0
- data/examples/example_pingudp.rb +12 -0
- data/lib/net/ping.rb +17 -0
- data/lib/net/ping/external.rb +126 -0
- data/lib/net/ping/http.rb +98 -0
- data/lib/net/ping/icmp.rb +165 -0
- data/lib/net/ping/ping.rb +88 -0
- data/lib/net/ping/tcp.rb +83 -0
- data/lib/net/ping/udp.rb +119 -0
- data/lib/net/ping/wmi.rb +118 -0
- data/net-ping.gemspec +38 -0
- data/test/test_net_ping.rb +26 -0
- data/test/test_net_ping_external.rb +87 -0
- data/test/test_net_ping_http.rb +115 -0
- data/test/test_net_ping_icmp.rb +126 -0
- data/test/test_net_ping_tcp.rb +108 -0
- data/test/test_net_ping_udp.rb +122 -0
- data/test/test_net_ping_wmi.rb +84 -0
- metadata +129 -0
data/CHANGES
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
== 1.3.3 - 21-Jun-2010
|
2
|
+
* Bug fixes for JRuby on MS Windows. The code now explicitly checks for JRuby
|
3
|
+
in a few places to ensure it doesn't try to load unsupported libraries
|
4
|
+
on MS Windows. Thanks go to Rob Schultz for the spot and some patches.
|
5
|
+
* The Net::Ping::HTTP class will no longer fail because a root URI
|
6
|
+
is missing a trailing slash. If the URI#path is empty, it now defaults
|
7
|
+
to the root path.
|
8
|
+
* The Rakefile tasks and naming were refactored.
|
9
|
+
* Some tests were refactored to take advantage of test-unit 2.x features,
|
10
|
+
as well as make them better and more descriptive in general.
|
11
|
+
|
12
|
+
== 1.3.2 - 21-Sep-2009
|
13
|
+
* Doing a 'require "net/ping"' was not automatically loading the
|
14
|
+
Net::Ping::WMI class on MS Windows. This has been fixed. Thanks go to
|
15
|
+
Joseph M. for the spot.
|
16
|
+
* Removed all $LOAD_PATH mangling for both the library and tests.
|
17
|
+
* Fixed a bug in the Net::Ping::HTTP class where a failed redirect did
|
18
|
+
not set the @exception and @warning instance variables properly.
|
19
|
+
* The PingStatus struct returned by Net::Ping::WMI is now frozen.
|
20
|
+
* The test-unit library was switched from a runtime dependency to a
|
21
|
+
development dependency.
|
22
|
+
* Added the :gem Rake task that builds a gem.
|
23
|
+
* Updated the :gem_install task to use the :gem task as a prerequisite.
|
24
|
+
* Updated the dependencies for MS Windows.
|
25
|
+
* The Rake test tasks are now more Rakish, e.g. test:tcp instead of test_tcp.
|
26
|
+
* Renamed example file names to avoid any potential confusion with actual
|
27
|
+
test files.
|
28
|
+
|
29
|
+
== 1.3.1 - 22-Jul-2009
|
30
|
+
* Removed class aliases, e.g. use Ping::External, not PingExternal.
|
31
|
+
* Minor code change to eliminate a warning that popped up in 1.9.x.
|
32
|
+
* The win32-open3 library is removed as a dependency for Ruby 1.9.x.
|
33
|
+
* Changed license to Artistic 2.0.
|
34
|
+
* Some gemspec and README updates.
|
35
|
+
|
36
|
+
== 1.3.0 - 19-May-2009
|
37
|
+
* Added the Ping::WMI class for MS Windows. This class encapsulates the
|
38
|
+
Win32_PingStatus WMI class. Unlike other ping methods, this one returns
|
39
|
+
a struct that contains various bits of information.
|
40
|
+
* The Net::Ping::External class now ensures that handles opened by the open3
|
41
|
+
call are closed. Thanks go to Nick S. Kanakakorn for the spot and a
|
42
|
+
preliminary patch.
|
43
|
+
* The Net::Ping::ICMP class now explicitly closes the socket if the call to
|
44
|
+
the Socket.pack_sockaddr_in method fails.
|
45
|
+
* Some documentation updates.
|
46
|
+
|
47
|
+
== 1.2.3 - 13-Jan-2008
|
48
|
+
* Fixed a bug in the checksum private method where it would die on odd data
|
49
|
+
sizes. Thanks go to Jake Douglas for the spot.
|
50
|
+
* A Socket.get_sockaddr_in call in the Ping::ICMP class is no longer included
|
51
|
+
as part of the overall ping time. Thanks go again to Jake Douglas for
|
52
|
+
the spot.
|
53
|
+
* Added data_size tests to the Ping::ICMP test suite.
|
54
|
+
* Renamed and updated the test files. The test-unit 2.x gem is now a
|
55
|
+
prerequisite as a result.
|
56
|
+
|
57
|
+
== 1.2.2 - 22-Jan-2008
|
58
|
+
* Bug fix for Ping::External where it was not honoring the timeout value.
|
59
|
+
Thanks go to Chris Morris for the spot and the patch.
|
60
|
+
* Bug fix for Ping::External where non-English output could cause false
|
61
|
+
positives on MS Windows Vista or later. This library now requires the
|
62
|
+
windows-pr library on MS Windows systems as a result.
|
63
|
+
* Added the Ping::UDP.service_check and Ping::UDP.service_check= class
|
64
|
+
methods. This method controls whether or not Errno::ECONNREFUSED or
|
65
|
+
Errno::ECONNRESET are considered successful pings or not.
|
66
|
+
* The Ping::HTTP class no longer uses the resolv-replace library on MS Windows
|
67
|
+
because it was (ironically) causing timeouts.
|
68
|
+
* Changed the Ping::TCP.econnrefused method to Ping::TCP.service_check. I
|
69
|
+
changed it because I now use a similar method in Ping::UDP, but that handles
|
70
|
+
more than Errno::ECONNREFUSED. An alias is provided to provide backwards
|
71
|
+
compatibility, but it is considered deprecated and will be removed in the
|
72
|
+
1.3.0 release.
|
73
|
+
* Removed the install.rb file. The Rakefile now handles installation.
|
74
|
+
|
75
|
+
== 1.2.1 - 6-Apr-2007
|
76
|
+
* For the Ping::External class, if a ping attempt results in 100% packet loss
|
77
|
+
it is now considered a failed ping, regardless of whether or not an error
|
78
|
+
was sent to stdout.
|
79
|
+
* Fixed the Ping::External class for OS X.
|
80
|
+
* Added a Rakefile. Installation and testing should now be run via Rake tasks.
|
81
|
+
* Minor fix for the Ping::ICMP class where I had accidentally dup'd some
|
82
|
+
aliases. This was harmless, but did cause warnings with -w.
|
83
|
+
|
84
|
+
== 1.2.0 - 5-Dec-2006
|
85
|
+
* Internal reorganization - each class now lives in its own file.
|
86
|
+
* Added the Ping::ICMP class. Thanks go to Jos Backus for contributing a
|
87
|
+
large part of the code.
|
88
|
+
* The host argument is now optional in the constructor. You can now specify
|
89
|
+
it in the ping method instead. Note that it must be specified in one place
|
90
|
+
or the other.
|
91
|
+
* Each PingXXX class is now Ping::XXX instead. However, class name aliases
|
92
|
+
have been setup for backwards compatibility for now.
|
93
|
+
* The constructor for each Ping types now yields self.
|
94
|
+
* Added the pingecho alias for the ping method for each Ping type.
|
95
|
+
* Added the Ping::HTTP#follow_redirect accessor.
|
96
|
+
* The Ping::HTTP#ping method now honors the timeout value.
|
97
|
+
* The Ping::HTTP class now follows redirects automatically, though this is
|
98
|
+
configurable with the follow_redirect accessor.
|
99
|
+
* The Ping::TCP.ecr and Ping::TCP.ecr= methods are now true class method
|
100
|
+
aliases (they were just wrappers previously).
|
101
|
+
* The Ping::UDP class now enforces a 64 character limit on data that can be
|
102
|
+
sent on a udp ping.
|
103
|
+
* Updated the gemspec. Specifically, MS Windows now has a dependency on
|
104
|
+
the win32-open3 package.
|
105
|
+
* Added inline rdoc.
|
106
|
+
|
107
|
+
== 1.1.1 - 15-Jun-2006
|
108
|
+
* Fixed a bug in PingTCP (bad variable name). Thanks go to Anoop Chandran
|
109
|
+
for the spot.
|
110
|
+
* Minor variable name refactoring.
|
111
|
+
* Minor test updates.
|
112
|
+
|
113
|
+
== 1.1.0 - 17-Jul-2005
|
114
|
+
* Fixed a bug in the PingHTTP#ping method where I was accidentally passing
|
115
|
+
the timeout value instead of the port number as the third argument to
|
116
|
+
Net::HTTP.get_response.
|
117
|
+
* The PingHTTP.new method now has a default port of 80.
|
118
|
+
* Minor doc update for PingHTTP.new.
|
119
|
+
|
120
|
+
== 1.0.1 - 22-Jun-2005
|
121
|
+
* Bug fix for the install.rb file. The gem is unaffected.
|
122
|
+
|
123
|
+
== 1.0.0 - 14-Jun-2005
|
124
|
+
* Renamed project from net-pingsimple to just net-ping.
|
125
|
+
* Added a PingHTTP subclass.
|
126
|
+
* Moved project to RubyForge.
|
127
|
+
* Added a gemspec.
|
128
|
+
|
129
|
+
== 0.3.1 - 9-Apr-2005
|
130
|
+
* Updated PingExternal to use win32/open3 on Win32 platforms.
|
131
|
+
* Minor error handling change for the PingSimple.econnrefused= method. It now
|
132
|
+
raises an ArgumentError if any values other than true or false are passed.
|
133
|
+
* PingSimple#warning and PingSimple#exception are now read-only methods.
|
134
|
+
* The warning and exception attributes are now reset to nil between each call
|
135
|
+
to ping.
|
136
|
+
* The data and data= methods are now unique to the PingUDP class.
|
137
|
+
* The time and time= methods have been changed to timeout and timeout=,
|
138
|
+
respectively.
|
139
|
+
* Removed the pingsimple.rd and pingsimple.html files. The pingsimple.txt file
|
140
|
+
has been reorganized and is now rdoc friendly.
|
141
|
+
* Added a few sample programs under the 'examples' directory.
|
142
|
+
* Some minor test updates and changes.
|
143
|
+
* Removed the INSTALL file. That information is now in the README file.
|
144
|
+
* Now requires Ruby 1.8.0 or later.
|
145
|
+
|
146
|
+
== 0.3.0 - 12-Feb-2004
|
147
|
+
* Fixed ping string for PingExternal class based on platform. The old
|
148
|
+
string was really only good for Linux and *BSD.
|
149
|
+
* Added Win32 support (requires win32_popen package).
|
150
|
+
* Added warranty info.
|
151
|
+
|
152
|
+
== 0.2.3 - 12-Aug-2003
|
153
|
+
* Fixed a bug in PingExternal that could consume file descriptors if used in a loop
|
154
|
+
* Added some initialization to avoid -w warnings
|
155
|
+
* Removed VERSION() class method. Use the constant instead
|
156
|
+
* Modified test suite slightly
|
157
|
+
* Moved rd2 docs to doc directory
|
158
|
+
|
159
|
+
== 0.2.2 - 3-Apr-2003
|
160
|
+
* Fixed handling of stdout in PingExternal
|
161
|
+
|
162
|
+
== 0.2.1 - 27-Mar-2003
|
163
|
+
* Fixed major bug with PingExternal class with regards to down hosts
|
164
|
+
* Exceptions and warnings from PingExternal are now chomp'd
|
165
|
+
* Modified test suite
|
166
|
+
* Doc updates
|
167
|
+
|
168
|
+
== 0.2.0 - 14-Feb-2003
|
169
|
+
* The default behavior of PingTCP with regards to ECONNREFUSED is now
|
170
|
+
configurable
|
171
|
+
* Added a VERSION constant and method (to the base class)
|
172
|
+
* Added a test suite (for those with testunit installed)
|
173
|
+
* Doc changes, rearrangement and general cleanup
|
174
|
+
* Manifest is now MANIFEST
|
175
|
+
* Added an INSTALL file
|
176
|
+
|
177
|
+
== 0.1.0 - 9-Dec-2002
|
178
|
+
* Added ping? alias for ping method
|
179
|
+
* Warnings now handled separately
|
180
|
+
* Corrected a mis-named variable in Ping::External
|
181
|
+
* Fixed the install.rb file
|
182
|
+
* Updated and added docs
|
183
|
+
* Renamed tarball to net-pingsimple to reflect RAA naming convention
|
184
|
+
|
185
|
+
== 0.0.1a
|
186
|
+
* Did this release ever happen?
|
187
|
+
|
188
|
+
== 0.0.1
|
189
|
+
* Initial release.
|
data/MANIFEST
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
* MANIFEST
|
2
|
+
* CHANGES
|
3
|
+
* Rakefile
|
4
|
+
* README
|
5
|
+
* net-ping.gemspec
|
6
|
+
* examples/example_pingexternal.rb
|
7
|
+
* examples/example_pinghttp.rb
|
8
|
+
* examples/example_pingtcp.rb
|
9
|
+
* examples/example_pingudp.rb
|
10
|
+
* lib/net/ping.rb
|
11
|
+
* lib/net/ping/icmp.rb
|
12
|
+
* lib/net/ping/tcp.rb
|
13
|
+
* lib/net/ping/udp.rb
|
14
|
+
* lib/net/ping/wmi.rb
|
15
|
+
* lib/net/ping/http.rb
|
16
|
+
* lib/net/ping/external.rb
|
17
|
+
* test/test_net_ping_external.rb
|
18
|
+
* test/test_net_ping_http.rb
|
19
|
+
* test/test_net_ping_icmp.rb
|
20
|
+
* test/test_net_ping_tcp.rb
|
21
|
+
* test/test_net_ping_udp.rb
|
22
|
+
* test/test_net_ping_wmi.rb
|
23
|
+
* test/test_net_ping.rb
|
data/README
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
== Description
|
2
|
+
A collection of classes that provide different ways to ping computers.
|
3
|
+
|
4
|
+
== Prerequisites
|
5
|
+
* Ruby 1.8.0 or later
|
6
|
+
* The win32-open3 (1.8.x) and windows-pr libraries are required on
|
7
|
+
MS Windows when using the Net::Ping::External class unless you're
|
8
|
+
using JRuby.
|
9
|
+
* Windows 2000 or later is required to use the Ping::WMI class.
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
gem install net-ping
|
13
|
+
|
14
|
+
== Notes
|
15
|
+
Please read the documentation under the 'doc' directory. Especially pay
|
16
|
+
attention to the documentation pertaining to ECONNREFUSED and TCP pings.
|
17
|
+
|
18
|
+
Also note the documentation regarding down hosts.
|
19
|
+
|
20
|
+
You do not need win32-open3 with Ruby 1.9.x. The open3 library that ships
|
21
|
+
as part of the Ruby standard library should work.
|
22
|
+
|
23
|
+
== How to require net-ping
|
24
|
+
You can do either this:
|
25
|
+
|
26
|
+
require 'net/ping'
|
27
|
+
|
28
|
+
In which case you will get Net::Ping and all of its subclasses. Or,
|
29
|
+
you can load individual subclasses like this:
|
30
|
+
|
31
|
+
require 'net/ping/tcp'
|
32
|
+
|
33
|
+
The former has the advantage of being easier to remember and all inclusive,
|
34
|
+
not to mention backwards compatible. The latter has the advantage of
|
35
|
+
reducing your memory footprint.
|
36
|
+
|
37
|
+
== Known Issues
|
38
|
+
Older versions of Ruby 1.9.x may not work with UDP pings.
|
39
|
+
As of JRuby 1.5.1, UDP pings will return false positives because of an
|
40
|
+
incorrect error class being raised. See JRuby-4896.
|
41
|
+
|
42
|
+
== License
|
43
|
+
Artistic 2.0
|
44
|
+
|
45
|
+
== More documentation
|
46
|
+
If you installed this library via Rubygems, you can view the inline
|
47
|
+
documentation via ri or fire up 'gem server', and point your browser at
|
48
|
+
http://localhost:8808.
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
include Config
|
4
|
+
|
5
|
+
namespace 'gem' do
|
6
|
+
desc 'Create the net-ping gem'
|
7
|
+
task :create do
|
8
|
+
spec = eval(IO.read('net-ping.gemspec'))
|
9
|
+
Gem::Builder.new(spec).build
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'Install the net-ping gem'
|
13
|
+
task :install => [:create] do
|
14
|
+
gem_file = Dir["*.gem"].first
|
15
|
+
sh "gem install #{gem_file}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace 'example' do
|
20
|
+
desc 'Run the external ping example program'
|
21
|
+
task :external do
|
22
|
+
ruby '-Ilib examples/example_pingexternal.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Run the http ping example program'
|
26
|
+
task :http do
|
27
|
+
ruby '-Ilib examples/example_pinghttp.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run the tcp ping example program'
|
31
|
+
task :tcp do
|
32
|
+
ruby '-Ilib examples/example_pingtcp.rb'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Run the udp ping example program'
|
36
|
+
task :udp do
|
37
|
+
ruby '-Ilib examples/example_pingudp.rb'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::TestTask.new do |t|
|
42
|
+
t.libs << 'test'
|
43
|
+
t.warning = true
|
44
|
+
t.verbose = true
|
45
|
+
t.test_files = FileList['test/test_net_ping.rb']
|
46
|
+
end
|
47
|
+
|
48
|
+
namespace 'test' do
|
49
|
+
Rake::TestTask.new('external') do |t|
|
50
|
+
t.warning = true
|
51
|
+
t.verbose = true
|
52
|
+
t.test_files = FileList['test/test_net_ping_external.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
Rake::TestTask.new('http') do |t|
|
56
|
+
t.warning = true
|
57
|
+
t.verbose = true
|
58
|
+
t.test_files = FileList['test/test_net_ping_http.rb']
|
59
|
+
end
|
60
|
+
|
61
|
+
Rake::TestTask.new('icmp') do |t|
|
62
|
+
t.warning = true
|
63
|
+
t.verbose = true
|
64
|
+
t.test_files = FileList['test/test_net_ping_icmp.rb']
|
65
|
+
end
|
66
|
+
|
67
|
+
Rake::TestTask.new('tcp') do |t|
|
68
|
+
t.warning = true
|
69
|
+
t.verbose = true
|
70
|
+
t.test_files = FileList['test/test_net_ping_tcp.rb']
|
71
|
+
end
|
72
|
+
|
73
|
+
Rake::TestTask.new('udp') do |t|
|
74
|
+
t.warning = true
|
75
|
+
t.verbose = true
|
76
|
+
t.test_files = FileList['test/test_net_ping_udp.rb']
|
77
|
+
end
|
78
|
+
|
79
|
+
Rake::TestTask.new('wmi') do |t|
|
80
|
+
t.warning = true
|
81
|
+
t.verbose = true
|
82
|
+
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
83
|
+
end
|
84
|
+
end
|
data/doc/ping.txt
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
= Description
|
2
|
+
A simple Ruby interface to the 'ping' command.
|
3
|
+
|
4
|
+
= Synopsis
|
5
|
+
require 'net/ping'
|
6
|
+
include Net
|
7
|
+
|
8
|
+
Ping::TCP.service_check = true
|
9
|
+
|
10
|
+
pt = Net::Ping::TCP.new(host)
|
11
|
+
pu = Net::Ping::UDP.new(host)
|
12
|
+
pe = Net::Ping::External.new(host)
|
13
|
+
ph = Net::Ping::HTTP.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
|
+
* Ping::TCP
|
41
|
+
* Ping::UDP
|
42
|
+
* Ping::External
|
43
|
+
* Ping::HTTP
|
44
|
+
* Ping::ICMP
|
45
|
+
* Ping::WMI
|
46
|
+
|
47
|
+
All Ping classes are children of the Ping parent class (which should
|
48
|
+
never be instantiated directly).
|
49
|
+
|
50
|
+
The Ping::ICMP class requires root privileges on UNIX systems.
|
51
|
+
|
52
|
+
The Ping::WMI class only works on MS Windows.
|
53
|
+
|
54
|
+
== Net::Ping
|
55
|
+
Net::Ping.new(host=nil, port=7, timeout=5)
|
56
|
+
Creates and returns a new Ping object. If the host is not specified
|
57
|
+
in the constructor then it must be specified in the ping method.
|
58
|
+
|
59
|
+
== Net::Ping::TCP
|
60
|
+
Ping::TCP.service_check
|
61
|
+
Returns the setting for how ECONNREFUSED is handled. By default, this is
|
62
|
+
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
63
|
+
|
64
|
+
Ping::TCP.service_check=(bool)
|
65
|
+
Sets the behavior for how ECONNREFUSED is handled. By default, this is
|
66
|
+
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
67
|
+
|
68
|
+
Ping::TCP#ping(host=nil)
|
69
|
+
Attempts to open a connection using TCPSocket with a +host+ specified
|
70
|
+
either here or in the constructor. A successful open means the ping was
|
71
|
+
successful and true is returned. Otherwise, false is returned.
|
72
|
+
|
73
|
+
== Net::Ping::UDP
|
74
|
+
Ping::UDP#ping
|
75
|
+
Attempts to open a connection using UDPSocket and sends the value of
|
76
|
+
Ping::UDP#data as a string across the socket. If the return string matches,
|
77
|
+
then the ping was successful and true is returned. Otherwise, false is
|
78
|
+
returned.
|
79
|
+
|
80
|
+
Ping::UDP#data
|
81
|
+
Returns the string that is sent across the UDP socket.
|
82
|
+
|
83
|
+
Ping::UDP#data=(string)
|
84
|
+
Sets the string that is sent across the UDP socket. The default is "ping".
|
85
|
+
Note that the +string+ cannot be larger than MAX_DATA (64 characters).
|
86
|
+
|
87
|
+
== Net::Ping::External
|
88
|
+
Ping::External#ping
|
89
|
+
Uses the 'open3' module and calls your system's local 'ping' command with
|
90
|
+
various options, depending on platform. If nothing is sent to stderr, the
|
91
|
+
ping was successful and true is returned. Otherwise, false is returned.
|
92
|
+
|
93
|
+
The MS Windows platform requires the 'win32-open3' package.
|
94
|
+
|
95
|
+
== Ping::HTTP
|
96
|
+
Ping::HTTP.new(uri=nil, port=80, timeout=5)
|
97
|
+
Identical to Net::Ping.new except that, instead of a host, the first
|
98
|
+
argument is a URI.
|
99
|
+
|
100
|
+
Ping::HTTP#ping
|
101
|
+
Checks for a response against +uri+. As long as kind of Net::HTTPSuccess
|
102
|
+
response is returned, the ping is successful and true is returned.
|
103
|
+
Otherwise, false is returned and Ping::HTTP#exception is set to the error
|
104
|
+
message.
|
105
|
+
|
106
|
+
Note that redirects are automatically followed unless the
|
107
|
+
Ping::HTTP#follow_redirects method is set to false.
|
108
|
+
|
109
|
+
Ping::HTTP#follow_redirect
|
110
|
+
Indicates whether or not a redirect should be followed in a ping attempt.
|
111
|
+
By default this is set to true.
|
112
|
+
|
113
|
+
Ping::HTTP#follow_redirect=(bool)
|
114
|
+
Sets whether or not a redirect should be followed in a ping attempt. If
|
115
|
+
set to false, then any redirect is considered a failed ping.
|
116
|
+
|
117
|
+
Ping::HTTP#uri
|
118
|
+
An alias for Ping::HTTP#host.
|
119
|
+
|
120
|
+
Ping::HTTP#uri=(uri)
|
121
|
+
An alias for Ping::HTTP#host=.
|
122
|
+
|
123
|
+
== Ping::ICMP
|
124
|
+
Ping::ICMP#duration
|
125
|
+
The time it took to ping the host. Not a precise value but a good estimate.
|
126
|
+
|
127
|
+
== Ping::WMI
|
128
|
+
Ping::WMI#ping(host, options={})
|
129
|
+
Unlike other Ping classes, this method returns a PingStatus struct that
|
130
|
+
contains various bits of information about the ping itself. The PingStatus
|
131
|
+
struct is a wrapper for the Win32_PingStatus WMI class.
|
132
|
+
|
133
|
+
In addition, you can pass options that will be interpreted as WQL parameters.
|
134
|
+
|
135
|
+
Ping::WMI#ping?(host, options={})
|
136
|
+
Returns whether or not the ping succeeded.
|
137
|
+
|
138
|
+
= Common Instance Methods
|
139
|
+
Ping#exception
|
140
|
+
Returns the error string that was set if a ping call failed. If an exception
|
141
|
+
is raised, it is caught and stored in this attribute. It is not raised in
|
142
|
+
your code.
|
143
|
+
|
144
|
+
This should be nil if the ping succeeded.
|
145
|
+
|
146
|
+
Ping#host
|
147
|
+
Returns the host name that ping attempts will ping against.
|
148
|
+
|
149
|
+
Ping#host=(hostname)
|
150
|
+
Sets the host name that ping attempts will ping against.
|
151
|
+
|
152
|
+
Ping#port
|
153
|
+
Returns the port number that ping attempts will use.
|
154
|
+
|
155
|
+
Ping#port=(port)
|
156
|
+
Set the port number to open socket connections on. The default is 7 (or
|
157
|
+
whatever your 'echo' port is set to). Note that you can also specify a
|
158
|
+
string, such as "http".
|
159
|
+
|
160
|
+
Ping#timeout
|
161
|
+
Returns the amount of time before the timeout module raises a TimeoutError
|
162
|
+
during connection attempts. The default is 5 seconds.
|
163
|
+
|
164
|
+
Ping#timeout=(time)
|
165
|
+
Sets the amount of time before the timeout module raises a TimeoutError.
|
166
|
+
during connection attempts.
|
167
|
+
|
168
|
+
Ping#warning
|
169
|
+
Returns a warning string that was returned during the ping attempt. This
|
170
|
+
typically occurs only in the Ping::External class, or the Ping::HTTP class
|
171
|
+
if a redirect occurred.
|
172
|
+
|
173
|
+
== Notes
|
174
|
+
If a host is down *IT IS CONSIDERED A FAILED PING*, and the 'no answer from
|
175
|
+
+host+' text is assigned to the 'exception' attribute. You may disagree with
|
176
|
+
this behavior, in which case you need merely check the exception attribute
|
177
|
+
against a regex as a simple workaround.
|
178
|
+
|
179
|
+
== Pre-emptive FAQ
|
180
|
+
Q: "Why don't you return exceptions if a connection fails?"
|
181
|
+
|
182
|
+
A: Because ping is only meant to return one of two things - success or
|
183
|
+
failure. It's very simple. If you want to find out *why* the ping
|
184
|
+
failed, you can check the 'exception' attribute.
|
185
|
+
|
186
|
+
Q: "I know the host is alive, but a TCP or UDP ping tells me otherwise. What
|
187
|
+
gives?"
|
188
|
+
|
189
|
+
A: It's possible that the echo port has been disabled on the remote
|
190
|
+
host for security reasons. Your best best is to specify a different port
|
191
|
+
or to use Ping::ICMP or Ping::External instead.
|
192
|
+
|
193
|
+
In the case of UDP pings, they are often actively refused. It may be
|
194
|
+
more pragmatic to set Ping::UDP.service_check = false.
|
195
|
+
|
196
|
+
Q: "Why does a TCP ping return false when I know it should return true?"
|
197
|
+
|
198
|
+
A: By default ECONNREFUSED errors will return a value of false. This is
|
199
|
+
contrary to what most other folks do for TCP pings. The problem with
|
200
|
+
their philosophy is that you can get false positives if a firewall blocks
|
201
|
+
the route to the host. The problem with my philosophy is that you can
|
202
|
+
get false negatives if there is no firewall (or it's not blocking the
|
203
|
+
route). Given the alternatives I chose the latter.
|
204
|
+
|
205
|
+
You can always change the default behavior by using the +service_check+
|
206
|
+
class method.
|
207
|
+
|
208
|
+
A similar situation is true for UDP pings.
|
209
|
+
|
210
|
+
Q: "Couldn't you use traceroute information to tell for sure?"
|
211
|
+
|
212
|
+
A: I could but I won't so don't bug me about it. It's far more effort than
|
213
|
+
it's worth. If you want something like that, please port the
|
214
|
+
Net::Traceroute Perl module by Daniel Hagerty.
|
215
|
+
|
216
|
+
= Known Bugs
|
217
|
+
You may see a test failure from the test_net_ping_tcp test case. You can
|
218
|
+
ignore these.
|
219
|
+
|
220
|
+
The socket library that ships with the Windows One-Click installer has
|
221
|
+
known issues. This may cause the Ping::ICMP class to fail. In fact, I
|
222
|
+
make an effort to skip those tests if I detect the one-click installer.
|
223
|
+
|
224
|
+
UDP pings may not work with older versions of Ruby 1.9.x.
|
225
|
+
|
226
|
+
Please report any bugs on the project page at
|
227
|
+
http://www.rubyforge.org/projects/shards.
|
228
|
+
|
229
|
+
= Acknowledgements
|
230
|
+
The Ping::ICMP#ping method is based largely on the identical method from
|
231
|
+
the Net::Ping Perl module by Rob Brown. Much of the code was ported by
|
232
|
+
Jos Backus on ruby-talk.
|
233
|
+
|
234
|
+
= Future Plans
|
235
|
+
Add support for syn pings.
|
236
|
+
|
237
|
+
= License
|
238
|
+
Artistic 2.0
|
239
|
+
|
240
|
+
= Copyright
|
241
|
+
(C) 2003-2010 Daniel J. Berger, All Rights Reserved
|
242
|
+
|
243
|
+
= Warranty
|
244
|
+
This package is provided "as is" and without any express or
|
245
|
+
implied warranties, including, without limitation, the implied
|
246
|
+
warranties of merchantability and fitness for a particular purpose.
|
247
|
+
|
248
|
+
= Author
|
249
|
+
Daniel J. Berger
|