net-ping 1.7.4-universal-mingw32 → 1.7.5-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/CHANGES +340 -334
- data/Gemfile +2 -2
- data/MANIFEST +25 -24
- data/README +66 -62
- data/Rakefile +94 -94
- data/doc/ping.txt +246 -246
- data/examples/example_pingexternal.rb +16 -16
- data/examples/example_pinghttp.rb +22 -22
- data/examples/example_pingtcp.rb +16 -16
- data/examples/example_pingudp.rb +12 -12
- data/lib/net/ping.rb +17 -17
- data/lib/net/ping/external.rb +101 -93
- data/lib/net/ping/http.rb +188 -188
- data/lib/net/ping/icmp.rb +179 -179
- data/lib/net/ping/ping.rb +89 -89
- data/lib/net/ping/tcp.rb +107 -102
- data/lib/net/ping/udp.rb +119 -119
- data/lib/net/ping/wmi.rb +118 -118
- data/net-ping.gemspec +39 -39
- data/test/test_net_ping.rb +35 -35
- data/test/test_net_ping_external.rb +143 -143
- data/test/test_net_ping_http.rb +240 -240
- data/test/test_net_ping_icmp.rb +186 -186
- data/test/test_net_ping_tcp.rb +105 -105
- data/test/test_net_ping_udp.rb +119 -119
- data/test/test_net_ping_wmi.rb +81 -81
- metadata +22 -20
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
gemspec
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
gemspec
|
data/MANIFEST
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
*
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
* examples/
|
8
|
-
* examples/
|
9
|
-
* examples/
|
10
|
-
*
|
11
|
-
* lib/net/ping
|
12
|
-
* lib/net/ping/
|
13
|
-
* lib/net/ping/
|
14
|
-
* lib/net/ping/
|
15
|
-
* lib/net/ping/
|
16
|
-
* lib/net/ping/
|
17
|
-
*
|
18
|
-
* test/
|
19
|
-
* test/
|
20
|
-
* test/
|
21
|
-
* test/
|
22
|
-
* test/
|
23
|
-
* test/
|
24
|
-
* test/
|
1
|
+
* CHANGES
|
2
|
+
* Gemfile
|
3
|
+
* MANIFEST
|
4
|
+
* Rakefile
|
5
|
+
* README
|
6
|
+
* net-ping.gemspec
|
7
|
+
* examples/example_pingexternal.rb
|
8
|
+
* examples/example_pinghttp.rb
|
9
|
+
* examples/example_pingtcp.rb
|
10
|
+
* examples/example_pingudp.rb
|
11
|
+
* lib/net/ping.rb
|
12
|
+
* lib/net/ping/icmp.rb
|
13
|
+
* lib/net/ping/tcp.rb
|
14
|
+
* lib/net/ping/udp.rb
|
15
|
+
* lib/net/ping/wmi.rb
|
16
|
+
* lib/net/ping/http.rb
|
17
|
+
* lib/net/ping/external.rb
|
18
|
+
* test/test_net_ping_external.rb
|
19
|
+
* test/test_net_ping_http.rb
|
20
|
+
* test/test_net_ping_icmp.rb
|
21
|
+
* test/test_net_ping_ldap.rb
|
22
|
+
* test/test_net_ping_tcp.rb
|
23
|
+
* test/test_net_ping_udp.rb
|
24
|
+
* test/test_net_ping_wmi.rb
|
25
|
+
* test/test_net_ping.rb
|
data/README
CHANGED
@@ -1,62 +1,66 @@
|
|
1
|
-
== Description
|
2
|
-
A collection of classes that provide different ways to ping computers.
|
3
|
-
|
4
|
-
== Prerequisites
|
5
|
-
* ffi
|
6
|
-
* win32-security (MS Windows only)
|
7
|
-
* fakeweb (test only)
|
8
|
-
* test-unit (test only)
|
9
|
-
|
10
|
-
Ruby users should use Ruby 1.9.3 or later.
|
11
|
-
JRuby users should use JRuby 1.6.7 or later.
|
12
|
-
|
13
|
-
== Installation
|
14
|
-
gem install net-ping
|
15
|
-
|
16
|
-
==
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
1
|
+
== Description
|
2
|
+
A collection of classes that provide different ways to ping computers.
|
3
|
+
|
4
|
+
== Prerequisites
|
5
|
+
* ffi
|
6
|
+
* win32-security (MS Windows only)
|
7
|
+
* fakeweb (test only)
|
8
|
+
* test-unit (test only)
|
9
|
+
|
10
|
+
Ruby users should use Ruby 1.9.3 or later.
|
11
|
+
JRuby users should use JRuby 1.6.7 or later.
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
gem install net-ping
|
15
|
+
|
16
|
+
== Maintainer Wanted!
|
17
|
+
I would very much like to turn this gem over to someone who is using it
|
18
|
+
more actively than I am. Please let me know if you are interested!
|
19
|
+
|
20
|
+
== Notes
|
21
|
+
Please read the documentation under the 'doc' directory. Especially pay
|
22
|
+
attention to the documentation pertaining to ECONNREFUSED and TCP pings.
|
23
|
+
|
24
|
+
Also note the documentation regarding down hosts.
|
25
|
+
== How to require net-ping
|
26
|
+
You can do either this:
|
27
|
+
|
28
|
+
require 'net/ping'
|
29
|
+
|
30
|
+
In which case you will get Net::Ping and all of its subclasses. Or,
|
31
|
+
you can load individual subclasses like this:
|
32
|
+
|
33
|
+
require 'net/ping/tcp'
|
34
|
+
|
35
|
+
The former has the advantage of being easier to remember and all inclusive,
|
36
|
+
not to mention backwards compatible. The latter has the advantage of
|
37
|
+
reducing your memory footprint.
|
38
|
+
|
39
|
+
== Known Issues
|
40
|
+
Older versions of Ruby 1.9.x may not work with UDP pings.
|
41
|
+
|
42
|
+
Older versions of JRuby will return false positives in UDP pings
|
43
|
+
because of an incorrect error class being raised. See JRuby-4896.
|
44
|
+
|
45
|
+
JRuby 1.6.7 or later is required for external pings because of a bug
|
46
|
+
in earlier versions with open3 and stream handling.
|
47
|
+
|
48
|
+
ICMP pings will not work with JRuby without some sort of third-party
|
49
|
+
library support for raw sockets in Java, such as RockSaw.
|
50
|
+
|
51
|
+
== License
|
52
|
+
Artistic 2.0
|
53
|
+
|
54
|
+
== Contributions
|
55
|
+
Although this library is free, please consider having your company
|
56
|
+
setup a gittip if used by your company professionally.
|
57
|
+
|
58
|
+
http://www.gittip.com/djberg96/
|
59
|
+
|
60
|
+
== More documentation
|
61
|
+
If you installed this library via Rubygems, you can view the inline
|
62
|
+
documentation via ri or fire up 'gem server', and point your browser at
|
63
|
+
http://localhost:8808.
|
64
|
+
|
65
|
+
== Author
|
66
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -1,94 +1,94 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
include Object.const_defined?(:RbConfig) ? RbConfig : Config
|
5
|
-
|
6
|
-
CLEAN.include("**/*.gem", "**/*.rbc")
|
7
|
-
|
8
|
-
namespace 'gem' do
|
9
|
-
desc 'Create the net-ping gem'
|
10
|
-
task :create => [:clean] do
|
11
|
-
spec = eval(IO.read('net-ping.gemspec'))
|
12
|
-
if Gem::VERSION.to_f < 2.0
|
13
|
-
Gem::Builder.new(spec).build
|
14
|
-
else
|
15
|
-
require 'rubygems/package'
|
16
|
-
Gem::Package.build(spec)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
desc 'Install the net-ping gem'
|
21
|
-
task :install => [:create] do
|
22
|
-
gem_file = Dir["*.gem"].first
|
23
|
-
sh "gem install #{gem_file}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
namespace 'example' do
|
28
|
-
desc 'Run the external ping example program'
|
29
|
-
task :external do
|
30
|
-
ruby '-Ilib examples/example_pingexternal.rb'
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'Run the http ping example program'
|
34
|
-
task :http do
|
35
|
-
ruby '-Ilib examples/example_pinghttp.rb'
|
36
|
-
end
|
37
|
-
|
38
|
-
desc 'Run the tcp ping example program'
|
39
|
-
task :tcp do
|
40
|
-
ruby '-Ilib examples/example_pingtcp.rb'
|
41
|
-
end
|
42
|
-
|
43
|
-
desc 'Run the udp ping example program'
|
44
|
-
task :udp do
|
45
|
-
ruby '-Ilib examples/example_pingudp.rb'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
Rake::TestTask.new do |t|
|
50
|
-
t.libs << 'test'
|
51
|
-
t.warning = true
|
52
|
-
t.verbose = true
|
53
|
-
t.test_files = FileList['test/test_net_ping.rb']
|
54
|
-
end
|
55
|
-
|
56
|
-
namespace 'test' do
|
57
|
-
Rake::TestTask.new('external') do |t|
|
58
|
-
t.warning = true
|
59
|
-
t.verbose = true
|
60
|
-
t.test_files = FileList['test/test_net_ping_external.rb']
|
61
|
-
end
|
62
|
-
|
63
|
-
Rake::TestTask.new('http') do |t|
|
64
|
-
t.warning = true
|
65
|
-
t.verbose = true
|
66
|
-
t.test_files = FileList['test/test_net_ping_http.rb']
|
67
|
-
end
|
68
|
-
|
69
|
-
Rake::TestTask.new('icmp') do |t|
|
70
|
-
t.warning = true
|
71
|
-
t.verbose = true
|
72
|
-
t.test_files = FileList['test/test_net_ping_icmp.rb']
|
73
|
-
end
|
74
|
-
|
75
|
-
Rake::TestTask.new('tcp') do |t|
|
76
|
-
t.warning = true
|
77
|
-
t.verbose = true
|
78
|
-
t.test_files = FileList['test/test_net_ping_tcp.rb']
|
79
|
-
end
|
80
|
-
|
81
|
-
Rake::TestTask.new('udp') do |t|
|
82
|
-
t.warning = true
|
83
|
-
t.verbose = true
|
84
|
-
t.test_files = FileList['test/test_net_ping_udp.rb']
|
85
|
-
end
|
86
|
-
|
87
|
-
Rake::TestTask.new('wmi') do |t|
|
88
|
-
t.warning = true
|
89
|
-
t.verbose = true
|
90
|
-
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
task :default => :test
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
include Object.const_defined?(:RbConfig) ? RbConfig : Config
|
5
|
+
|
6
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
7
|
+
|
8
|
+
namespace 'gem' do
|
9
|
+
desc 'Create the net-ping gem'
|
10
|
+
task :create => [:clean] do
|
11
|
+
spec = eval(IO.read('net-ping.gemspec'))
|
12
|
+
if Gem::VERSION.to_f < 2.0
|
13
|
+
Gem::Builder.new(spec).build
|
14
|
+
else
|
15
|
+
require 'rubygems/package'
|
16
|
+
Gem::Package.build(spec)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Install the net-ping gem'
|
21
|
+
task :install => [:create] do
|
22
|
+
gem_file = Dir["*.gem"].first
|
23
|
+
sh "gem install -l #{gem_file}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace 'example' do
|
28
|
+
desc 'Run the external ping example program'
|
29
|
+
task :external do
|
30
|
+
ruby '-Ilib examples/example_pingexternal.rb'
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Run the http ping example program'
|
34
|
+
task :http do
|
35
|
+
ruby '-Ilib examples/example_pinghttp.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Run the tcp ping example program'
|
39
|
+
task :tcp do
|
40
|
+
ruby '-Ilib examples/example_pingtcp.rb'
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Run the udp ping example program'
|
44
|
+
task :udp do
|
45
|
+
ruby '-Ilib examples/example_pingudp.rb'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Rake::TestTask.new do |t|
|
50
|
+
t.libs << 'test'
|
51
|
+
t.warning = true
|
52
|
+
t.verbose = true
|
53
|
+
t.test_files = FileList['test/test_net_ping.rb']
|
54
|
+
end
|
55
|
+
|
56
|
+
namespace 'test' do
|
57
|
+
Rake::TestTask.new('external') do |t|
|
58
|
+
t.warning = true
|
59
|
+
t.verbose = true
|
60
|
+
t.test_files = FileList['test/test_net_ping_external.rb']
|
61
|
+
end
|
62
|
+
|
63
|
+
Rake::TestTask.new('http') do |t|
|
64
|
+
t.warning = true
|
65
|
+
t.verbose = true
|
66
|
+
t.test_files = FileList['test/test_net_ping_http.rb']
|
67
|
+
end
|
68
|
+
|
69
|
+
Rake::TestTask.new('icmp') do |t|
|
70
|
+
t.warning = true
|
71
|
+
t.verbose = true
|
72
|
+
t.test_files = FileList['test/test_net_ping_icmp.rb']
|
73
|
+
end
|
74
|
+
|
75
|
+
Rake::TestTask.new('tcp') do |t|
|
76
|
+
t.warning = true
|
77
|
+
t.verbose = true
|
78
|
+
t.test_files = FileList['test/test_net_ping_tcp.rb']
|
79
|
+
end
|
80
|
+
|
81
|
+
Rake::TestTask.new('udp') do |t|
|
82
|
+
t.warning = true
|
83
|
+
t.verbose = true
|
84
|
+
t.test_files = FileList['test/test_net_ping_udp.rb']
|
85
|
+
end
|
86
|
+
|
87
|
+
Rake::TestTask.new('wmi') do |t|
|
88
|
+
t.warning = true
|
89
|
+
t.verbose = true
|
90
|
+
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
task :default => :test
|
data/doc/ping.txt
CHANGED
@@ -1,246 +1,246 @@
|
|
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
|
-
* Ping::LDAP
|
47
|
-
|
48
|
-
All Ping classes are children of the Ping parent class (which should
|
49
|
-
never be instantiated directly).
|
50
|
-
|
51
|
-
The Ping::ICMP class requires root/administrative privileges.
|
52
|
-
|
53
|
-
The Ping::WMI class only works on MS Windows.
|
54
|
-
|
55
|
-
== Net::Ping
|
56
|
-
Net::Ping.new(host=nil, port=7, timeout=5)
|
57
|
-
Creates and returns a new Ping object. If the host is not specified
|
58
|
-
in the constructor then it must be specified in the ping method.
|
59
|
-
|
60
|
-
== Net::Ping::TCP
|
61
|
-
Ping::TCP.service_check
|
62
|
-
Returns the setting for how ECONNREFUSED is handled. By default, this is
|
63
|
-
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
64
|
-
|
65
|
-
Ping::TCP.service_check=(bool)
|
66
|
-
Sets the behavior for how ECONNREFUSED is handled. By default, this is
|
67
|
-
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
68
|
-
|
69
|
-
Ping::TCP#ping(host=nil)
|
70
|
-
Attempts to open a connection using TCPSocket with a +host+ specified
|
71
|
-
either here or in the constructor. A successful open means the ping was
|
72
|
-
successful and true is returned. Otherwise, false is returned.
|
73
|
-
|
74
|
-
== Net::Ping::UDP
|
75
|
-
Ping::UDP#ping
|
76
|
-
Attempts to open a connection using UDPSocket and sends the value of
|
77
|
-
Ping::UDP#data as a string across the socket. If the return string matches,
|
78
|
-
then the ping was successful and true is returned. Otherwise, false is
|
79
|
-
returned.
|
80
|
-
|
81
|
-
Ping::UDP#data
|
82
|
-
Returns the string that is sent across the UDP socket.
|
83
|
-
|
84
|
-
Ping::UDP#data=(string)
|
85
|
-
Sets the string that is sent across the UDP socket. The default is "ping".
|
86
|
-
Note that the +string+ cannot be larger than MAX_DATA (64 characters).
|
87
|
-
|
88
|
-
== Net::Ping::External
|
89
|
-
Ping::External#ping
|
90
|
-
Uses the 'open3' module and calls your system's local 'ping' command with
|
91
|
-
various options, depending on platform. If nothing is sent to stderr, the
|
92
|
-
ping was successful and true is returned. Otherwise, false is returned.
|
93
|
-
|
94
|
-
The MS Windows platform requires the 'win32-open3' package.
|
95
|
-
|
96
|
-
== Ping::HTTP
|
97
|
-
Ping::HTTP.new(uri=nil, port=80, timeout=5)
|
98
|
-
Identical to Net::Ping.new except that, instead of a host, the first
|
99
|
-
argument is a URI.
|
100
|
-
|
101
|
-
Ping::HTTP#ping
|
102
|
-
Checks for a response against +uri+. As long as kind of Net::HTTPSuccess
|
103
|
-
response is returned, the ping is successful and true is returned.
|
104
|
-
Otherwise, false is returned and Ping::HTTP#exception is set to the error
|
105
|
-
message.
|
106
|
-
|
107
|
-
Note that redirects are automatically followed unless the
|
108
|
-
Ping::HTTP#follow_redirects method is set to false.
|
109
|
-
|
110
|
-
Ping::HTTP#follow_redirect
|
111
|
-
Indicates whether or not a redirect should be followed in a ping attempt.
|
112
|
-
By default this is set to true.
|
113
|
-
|
114
|
-
Ping::HTTP#follow_redirect=(bool)
|
115
|
-
Sets whether or not a redirect should be followed in a ping attempt. If
|
116
|
-
set to false, then any redirect is considered a failed ping.
|
117
|
-
|
118
|
-
Ping::HTTP#uri
|
119
|
-
An alias for Ping::HTTP#host.
|
120
|
-
|
121
|
-
Ping::HTTP#uri=(uri)
|
122
|
-
An alias for Ping::HTTP#host=.
|
123
|
-
|
124
|
-
== Ping::ICMP
|
125
|
-
Ping::ICMP#duration
|
126
|
-
The time it took to ping the host. Not a precise value but a good estimate.
|
127
|
-
|
128
|
-
== Ping::WMI
|
129
|
-
Ping::WMI#ping(host, options={})
|
130
|
-
Unlike other Ping classes, this method returns a PingStatus struct that
|
131
|
-
contains various bits of information about the ping itself. The PingStatus
|
132
|
-
struct is a wrapper for the Win32_PingStatus WMI class.
|
133
|
-
|
134
|
-
In addition, you can pass options that will be interpreted as WQL parameters.
|
135
|
-
|
136
|
-
Ping::WMI#ping?(host, options={})
|
137
|
-
Returns whether or not the ping succeeded.
|
138
|
-
|
139
|
-
= Common Instance Methods
|
140
|
-
Ping#exception
|
141
|
-
Returns the error string that was set if a ping call failed. If an exception
|
142
|
-
is raised, it is caught and stored in this attribute. It is not raised in
|
143
|
-
your code.
|
144
|
-
|
145
|
-
This should be nil if the ping succeeded.
|
146
|
-
|
147
|
-
Ping#host
|
148
|
-
Returns the host name that ping attempts will ping against.
|
149
|
-
|
150
|
-
Ping#host=(hostname)
|
151
|
-
Sets the host name that ping attempts will ping against.
|
152
|
-
|
153
|
-
Ping#port
|
154
|
-
Returns the port number that ping attempts will use.
|
155
|
-
|
156
|
-
Ping#port=(port)
|
157
|
-
Set the port number to open socket connections on. The default is 7 (or
|
158
|
-
whatever your 'echo' port is set to). Note that you can also specify a
|
159
|
-
string, such as "http".
|
160
|
-
|
161
|
-
Ping#timeout
|
162
|
-
Returns the amount of time before the timeout module raises a TimeoutError
|
163
|
-
during connection attempts. The default is 5 seconds.
|
164
|
-
|
165
|
-
Ping#timeout=(time)
|
166
|
-
Sets the amount of time before the timeout module raises a TimeoutError.
|
167
|
-
during connection attempts.
|
168
|
-
|
169
|
-
Ping#warning
|
170
|
-
Returns a warning string that was returned during the ping attempt. This
|
171
|
-
typically occurs only in the Ping::External class, or the Ping::HTTP class
|
172
|
-
if a redirect occurred.
|
173
|
-
|
174
|
-
== Notes
|
175
|
-
If a host is down *IT IS CONSIDERED A FAILED PING*, and the 'no answer from
|
176
|
-
+host+' text is assigned to the 'exception' attribute. You may disagree with
|
177
|
-
this behavior, in which case you need merely check the exception attribute
|
178
|
-
against a regex as a simple workaround.
|
179
|
-
|
180
|
-
== Pre-emptive FAQ
|
181
|
-
Q: "Why don't you return exceptions if a connection fails?"
|
182
|
-
|
183
|
-
A: Because ping is only meant to return one of two things - success or
|
184
|
-
failure. It's very simple. If you want to find out *why* the ping
|
185
|
-
failed, you can check the 'exception' attribute.
|
186
|
-
|
187
|
-
Q: "I know the host is alive, but a TCP or UDP ping tells me otherwise. What
|
188
|
-
gives?"
|
189
|
-
|
190
|
-
A: It's possible that the echo port has been disabled on the remote
|
191
|
-
host for security reasons. Your best best is to specify a different port
|
192
|
-
or to use Ping::ICMP or Ping::External instead.
|
193
|
-
|
194
|
-
In the case of UDP pings, they are often actively refused. It may be
|
195
|
-
more pragmatic to set Ping::UDP.service_check = false.
|
196
|
-
|
197
|
-
Q: "Why does a TCP ping return false when I know it should return true?"
|
198
|
-
|
199
|
-
A: By default ECONNREFUSED errors will return a value of false. This is
|
200
|
-
contrary to what most other folks do for TCP pings. The problem with
|
201
|
-
their philosophy is that you can get false positives if a firewall blocks
|
202
|
-
the route to the host. The problem with my philosophy is that you can
|
203
|
-
get false negatives if there is no firewall (or it's not blocking the
|
204
|
-
route). Given the alternatives I chose the latter.
|
205
|
-
|
206
|
-
You can always change the default behavior by using the +service_check+
|
207
|
-
class method.
|
208
|
-
|
209
|
-
A similar situation is true for UDP pings.
|
210
|
-
|
211
|
-
Q: "Couldn't you use traceroute information to tell for sure?"
|
212
|
-
|
213
|
-
A: I could but I won't so don't bug me about it. It's far more effort than
|
214
|
-
it's worth. If you want something like that, please port the
|
215
|
-
Net::Traceroute Perl module by Daniel Hagerty.
|
216
|
-
|
217
|
-
= Known Bugs
|
218
|
-
You may see a test failure from the test_net_ping_tcp test case. You can
|
219
|
-
ignore these.
|
220
|
-
|
221
|
-
UDP pings may not work with older versions of Ruby 1.9.x.
|
222
|
-
|
223
|
-
Please report any bugs on the project page at
|
224
|
-
https://github.com/djberg96/net-ping
|
225
|
-
|
226
|
-
= Acknowledgements
|
227
|
-
The Ping::ICMP#ping method is based largely on the identical method from
|
228
|
-
the Net::Ping Perl module by Rob Brown. Much of the code was ported by
|
229
|
-
Jos Backus on ruby-talk.
|
230
|
-
|
231
|
-
= Future Plans
|
232
|
-
Add support for syn pings.
|
233
|
-
|
234
|
-
= License
|
235
|
-
Artistic 2.0
|
236
|
-
|
237
|
-
= Copyright
|
238
|
-
(C) 2003-2014 Daniel J. Berger, All Rights Reserved
|
239
|
-
|
240
|
-
= Warranty
|
241
|
-
This package is provided "as is" and without any express or
|
242
|
-
implied warranties, including, without limitation, the implied
|
243
|
-
warranties of merchantability and fitness for a particular purpose.
|
244
|
-
|
245
|
-
= Author
|
246
|
-
Daniel J. Berger
|
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
|
+
* Ping::LDAP
|
47
|
+
|
48
|
+
All Ping classes are children of the Ping parent class (which should
|
49
|
+
never be instantiated directly).
|
50
|
+
|
51
|
+
The Ping::ICMP class requires root/administrative privileges.
|
52
|
+
|
53
|
+
The Ping::WMI class only works on MS Windows.
|
54
|
+
|
55
|
+
== Net::Ping
|
56
|
+
Net::Ping.new(host=nil, port=7, timeout=5)
|
57
|
+
Creates and returns a new Ping object. If the host is not specified
|
58
|
+
in the constructor then it must be specified in the ping method.
|
59
|
+
|
60
|
+
== Net::Ping::TCP
|
61
|
+
Ping::TCP.service_check
|
62
|
+
Returns the setting for how ECONNREFUSED is handled. By default, this is
|
63
|
+
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
64
|
+
|
65
|
+
Ping::TCP.service_check=(bool)
|
66
|
+
Sets the behavior for how ECONNREFUSED is handled. By default, this is
|
67
|
+
set to false, i.e. an ECONNREFUSED error is considered a failed ping.
|
68
|
+
|
69
|
+
Ping::TCP#ping(host=nil)
|
70
|
+
Attempts to open a connection using TCPSocket with a +host+ specified
|
71
|
+
either here or in the constructor. A successful open means the ping was
|
72
|
+
successful and true is returned. Otherwise, false is returned.
|
73
|
+
|
74
|
+
== Net::Ping::UDP
|
75
|
+
Ping::UDP#ping
|
76
|
+
Attempts to open a connection using UDPSocket and sends the value of
|
77
|
+
Ping::UDP#data as a string across the socket. If the return string matches,
|
78
|
+
then the ping was successful and true is returned. Otherwise, false is
|
79
|
+
returned.
|
80
|
+
|
81
|
+
Ping::UDP#data
|
82
|
+
Returns the string that is sent across the UDP socket.
|
83
|
+
|
84
|
+
Ping::UDP#data=(string)
|
85
|
+
Sets the string that is sent across the UDP socket. The default is "ping".
|
86
|
+
Note that the +string+ cannot be larger than MAX_DATA (64 characters).
|
87
|
+
|
88
|
+
== Net::Ping::External
|
89
|
+
Ping::External#ping
|
90
|
+
Uses the 'open3' module and calls your system's local 'ping' command with
|
91
|
+
various options, depending on platform. If nothing is sent to stderr, the
|
92
|
+
ping was successful and true is returned. Otherwise, false is returned.
|
93
|
+
|
94
|
+
The MS Windows platform requires the 'win32-open3' package.
|
95
|
+
|
96
|
+
== Ping::HTTP
|
97
|
+
Ping::HTTP.new(uri=nil, port=80, timeout=5)
|
98
|
+
Identical to Net::Ping.new except that, instead of a host, the first
|
99
|
+
argument is a URI.
|
100
|
+
|
101
|
+
Ping::HTTP#ping
|
102
|
+
Checks for a response against +uri+. As long as kind of Net::HTTPSuccess
|
103
|
+
response is returned, the ping is successful and true is returned.
|
104
|
+
Otherwise, false is returned and Ping::HTTP#exception is set to the error
|
105
|
+
message.
|
106
|
+
|
107
|
+
Note that redirects are automatically followed unless the
|
108
|
+
Ping::HTTP#follow_redirects method is set to false.
|
109
|
+
|
110
|
+
Ping::HTTP#follow_redirect
|
111
|
+
Indicates whether or not a redirect should be followed in a ping attempt.
|
112
|
+
By default this is set to true.
|
113
|
+
|
114
|
+
Ping::HTTP#follow_redirect=(bool)
|
115
|
+
Sets whether or not a redirect should be followed in a ping attempt. If
|
116
|
+
set to false, then any redirect is considered a failed ping.
|
117
|
+
|
118
|
+
Ping::HTTP#uri
|
119
|
+
An alias for Ping::HTTP#host.
|
120
|
+
|
121
|
+
Ping::HTTP#uri=(uri)
|
122
|
+
An alias for Ping::HTTP#host=.
|
123
|
+
|
124
|
+
== Ping::ICMP
|
125
|
+
Ping::ICMP#duration
|
126
|
+
The time it took to ping the host. Not a precise value but a good estimate.
|
127
|
+
|
128
|
+
== Ping::WMI
|
129
|
+
Ping::WMI#ping(host, options={})
|
130
|
+
Unlike other Ping classes, this method returns a PingStatus struct that
|
131
|
+
contains various bits of information about the ping itself. The PingStatus
|
132
|
+
struct is a wrapper for the Win32_PingStatus WMI class.
|
133
|
+
|
134
|
+
In addition, you can pass options that will be interpreted as WQL parameters.
|
135
|
+
|
136
|
+
Ping::WMI#ping?(host, options={})
|
137
|
+
Returns whether or not the ping succeeded.
|
138
|
+
|
139
|
+
= Common Instance Methods
|
140
|
+
Ping#exception
|
141
|
+
Returns the error string that was set if a ping call failed. If an exception
|
142
|
+
is raised, it is caught and stored in this attribute. It is not raised in
|
143
|
+
your code.
|
144
|
+
|
145
|
+
This should be nil if the ping succeeded.
|
146
|
+
|
147
|
+
Ping#host
|
148
|
+
Returns the host name that ping attempts will ping against.
|
149
|
+
|
150
|
+
Ping#host=(hostname)
|
151
|
+
Sets the host name that ping attempts will ping against.
|
152
|
+
|
153
|
+
Ping#port
|
154
|
+
Returns the port number that ping attempts will use.
|
155
|
+
|
156
|
+
Ping#port=(port)
|
157
|
+
Set the port number to open socket connections on. The default is 7 (or
|
158
|
+
whatever your 'echo' port is set to). Note that you can also specify a
|
159
|
+
string, such as "http".
|
160
|
+
|
161
|
+
Ping#timeout
|
162
|
+
Returns the amount of time before the timeout module raises a TimeoutError
|
163
|
+
during connection attempts. The default is 5 seconds.
|
164
|
+
|
165
|
+
Ping#timeout=(time)
|
166
|
+
Sets the amount of time before the timeout module raises a TimeoutError.
|
167
|
+
during connection attempts.
|
168
|
+
|
169
|
+
Ping#warning
|
170
|
+
Returns a warning string that was returned during the ping attempt. This
|
171
|
+
typically occurs only in the Ping::External class, or the Ping::HTTP class
|
172
|
+
if a redirect occurred.
|
173
|
+
|
174
|
+
== Notes
|
175
|
+
If a host is down *IT IS CONSIDERED A FAILED PING*, and the 'no answer from
|
176
|
+
+host+' text is assigned to the 'exception' attribute. You may disagree with
|
177
|
+
this behavior, in which case you need merely check the exception attribute
|
178
|
+
against a regex as a simple workaround.
|
179
|
+
|
180
|
+
== Pre-emptive FAQ
|
181
|
+
Q: "Why don't you return exceptions if a connection fails?"
|
182
|
+
|
183
|
+
A: Because ping is only meant to return one of two things - success or
|
184
|
+
failure. It's very simple. If you want to find out *why* the ping
|
185
|
+
failed, you can check the 'exception' attribute.
|
186
|
+
|
187
|
+
Q: "I know the host is alive, but a TCP or UDP ping tells me otherwise. What
|
188
|
+
gives?"
|
189
|
+
|
190
|
+
A: It's possible that the echo port has been disabled on the remote
|
191
|
+
host for security reasons. Your best best is to specify a different port
|
192
|
+
or to use Ping::ICMP or Ping::External instead.
|
193
|
+
|
194
|
+
In the case of UDP pings, they are often actively refused. It may be
|
195
|
+
more pragmatic to set Ping::UDP.service_check = false.
|
196
|
+
|
197
|
+
Q: "Why does a TCP ping return false when I know it should return true?"
|
198
|
+
|
199
|
+
A: By default ECONNREFUSED errors will return a value of false. This is
|
200
|
+
contrary to what most other folks do for TCP pings. The problem with
|
201
|
+
their philosophy is that you can get false positives if a firewall blocks
|
202
|
+
the route to the host. The problem with my philosophy is that you can
|
203
|
+
get false negatives if there is no firewall (or it's not blocking the
|
204
|
+
route). Given the alternatives I chose the latter.
|
205
|
+
|
206
|
+
You can always change the default behavior by using the +service_check+
|
207
|
+
class method.
|
208
|
+
|
209
|
+
A similar situation is true for UDP pings.
|
210
|
+
|
211
|
+
Q: "Couldn't you use traceroute information to tell for sure?"
|
212
|
+
|
213
|
+
A: I could but I won't so don't bug me about it. It's far more effort than
|
214
|
+
it's worth. If you want something like that, please port the
|
215
|
+
Net::Traceroute Perl module by Daniel Hagerty.
|
216
|
+
|
217
|
+
= Known Bugs
|
218
|
+
You may see a test failure from the test_net_ping_tcp test case. You can
|
219
|
+
ignore these.
|
220
|
+
|
221
|
+
UDP pings may not work with older versions of Ruby 1.9.x.
|
222
|
+
|
223
|
+
Please report any bugs on the project page at
|
224
|
+
https://github.com/djberg96/net-ping
|
225
|
+
|
226
|
+
= Acknowledgements
|
227
|
+
The Ping::ICMP#ping method is based largely on the identical method from
|
228
|
+
the Net::Ping Perl module by Rob Brown. Much of the code was ported by
|
229
|
+
Jos Backus on ruby-talk.
|
230
|
+
|
231
|
+
= Future Plans
|
232
|
+
Add support for syn pings.
|
233
|
+
|
234
|
+
= License
|
235
|
+
Artistic 2.0
|
236
|
+
|
237
|
+
= Copyright
|
238
|
+
(C) 2003-2014 Daniel J. Berger, All Rights Reserved
|
239
|
+
|
240
|
+
= Warranty
|
241
|
+
This package is provided "as is" and without any express or
|
242
|
+
implied warranties, including, without limitation, the implied
|
243
|
+
warranties of merchantability and fitness for a particular purpose.
|
244
|
+
|
245
|
+
= Author
|
246
|
+
Daniel J. Berger
|