net-ping 1.2.3-x86-mswin32-60 → 1.3.0-x86-mswin32-60
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 +11 -0
- data/MANIFEST +2 -0
- data/README +6 -1
- data/Rakefile +7 -1
- data/doc/ping.txt +23 -5
- data/examples/test_pingexternal.rb +18 -0
- data/examples/test_pinghttp.rb +19 -0
- data/examples/test_pingtcp.rb +22 -0
- data/examples/test_pingudp.rb +15 -0
- data/lib/net/ping/external.rb +5 -0
- data/lib/net/ping/icmp.rb +1 -0
- data/lib/net/ping/ping.rb +7 -1
- data/lib/net/ping/wmi.rb +119 -0
- data/net-ping.gemspec +17 -18
- data/test/test_net_ping_external.rb +1 -1
- data/test/test_net_ping_http.rb +1 -1
- data/test/test_net_ping_icmp.rb +21 -1
- data/test/test_net_ping_tcp.rb +11 -7
- data/test/test_net_ping_udp.rb +1 -1
- data/test/test_net_ping_wmi.rb +88 -0
- metadata +21 -18
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.3.0 - 19-May-2009
|
2
|
+
* Added the Ping::WMI class for MS Windows. This class encapsulates the
|
3
|
+
Win32_PingStatus WMI class. Unlike other ping methods, this one returns
|
4
|
+
a struct that contains various bits of information.
|
5
|
+
* The Net::Ping::External class now ensures that handles opened by the open3
|
6
|
+
call are closed. Thanks go to Nick S. Kanakakorn for the spot and a
|
7
|
+
preliminary patch.
|
8
|
+
* The Net::Ping::ICMP class now explicitly closes the socket if the call to
|
9
|
+
the Socket.pack_sockaddr_in method fails.
|
10
|
+
* Some documentation updates.
|
11
|
+
|
1
12
|
== 1.2.3 - 13-Jan-2008
|
2
13
|
* Fixed a bug in the checksum private method where it would die on odd data
|
3
14
|
sizes. Thanks go to Jake Douglas for the spot.
|
data/MANIFEST
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
* lib/net/ping/icmp.rb
|
12
12
|
* lib/net/ping/tcp.rb
|
13
13
|
* lib/net/ping/udp.rb
|
14
|
+
* lib/net/ping/wmi.rb
|
14
15
|
* lib/net/ping/http.rb
|
15
16
|
* lib/net/ping/external.rb
|
16
17
|
* test/test_net_ping_external.rb
|
@@ -18,4 +19,5 @@
|
|
18
19
|
* test/test_net_ping_icmp.rb
|
19
20
|
* test/test_net_ping_tcp.rb
|
20
21
|
* test/test_net_ping_udp.rb
|
22
|
+
* test/test_net_ping_wmi.rb
|
21
23
|
* test/test_net_ping.rb
|
data/README
CHANGED
@@ -4,9 +4,14 @@
|
|
4
4
|
== Prerequisites
|
5
5
|
* Ruby 1.8.0 or later
|
6
6
|
* The win32-open3 and windows-pr libraries are required on MS Windows
|
7
|
-
|
7
|
+
when using the Net::Ping::External class.
|
8
|
+
* Windows 2000 or later is required to use the Ping::WMI class.
|
8
9
|
|
9
10
|
== Installation
|
11
|
+
=== Remote Installation
|
12
|
+
gem install net-ping
|
13
|
+
|
14
|
+
=== Local Installation
|
10
15
|
rake test (optional)
|
11
16
|
rake install (standard) OR rake gem_install (gems)
|
12
17
|
|
data/Rakefile
CHANGED
@@ -58,4 +58,10 @@ Rake::TestTask.new("test_udp") do |t|
|
|
58
58
|
t.warning = true
|
59
59
|
t.verbose = true
|
60
60
|
t.test_files = FileList['test/test_net_ping_udp.rb']
|
61
|
-
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Rake::TestTask.new("test_wmi") do |t|
|
64
|
+
t.warning = true
|
65
|
+
t.verbose = true
|
66
|
+
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
67
|
+
end
|
data/doc/ping.txt
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
A simple Ruby interface to the 'ping' command.
|
3
3
|
|
4
4
|
= Synopsis
|
5
|
-
require
|
5
|
+
require 'net/ping'
|
6
6
|
include Net
|
7
7
|
|
8
|
-
Ping::TCP.
|
8
|
+
Ping::TCP.service_check = true
|
9
9
|
|
10
10
|
pt = Net::Ping::TCP.new(host)
|
11
11
|
pu = Net::Ping::UDP.new(host)
|
@@ -42,12 +42,15 @@
|
|
42
42
|
* Ping::External
|
43
43
|
* Ping::HTTP
|
44
44
|
* Ping::ICMP
|
45
|
+
* Ping::WMI
|
45
46
|
|
46
47
|
All Ping classes are children of the Ping parent class (which should
|
47
48
|
never be instantiated directly).
|
48
49
|
|
49
50
|
The Ping::ICMP class requires root privileges on UNIX systems.
|
50
51
|
|
52
|
+
The Ping::WMI class only works on MS Windows.
|
53
|
+
|
51
54
|
== Net::Ping
|
52
55
|
Net::Ping.new(host=nil, port=7, timeout=5)
|
53
56
|
Creates and returns a new Ping object. If the host is not specified
|
@@ -121,6 +124,17 @@ Ping::HTTP#uri=(uri)
|
|
121
124
|
Ping::ICMP#duration
|
122
125
|
The time it took to ping the host. Not a precise value but a good estimate.
|
123
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
|
+
|
124
138
|
= Common Instance Methods
|
125
139
|
Ping#exception
|
126
140
|
Returns the error string that was set if a ping call failed. If an exception
|
@@ -200,8 +214,12 @@ Ping#warning
|
|
200
214
|
Net::Traceroute Perl module by Daniel Hagerty.
|
201
215
|
|
202
216
|
= Known Bugs
|
203
|
-
You may see a test failure from the
|
204
|
-
|
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.
|
205
223
|
|
206
224
|
Please report any bugs on the project page at
|
207
225
|
http://www.rubyforge.org/projects/shards.
|
@@ -218,7 +236,7 @@ Ping#warning
|
|
218
236
|
Ruby's
|
219
237
|
|
220
238
|
= Copyright
|
221
|
-
(C) 2003-
|
239
|
+
(C) 2003-2009 Daniel J. Berger, All Rights Reserved
|
222
240
|
|
223
241
|
= Warranty
|
224
242
|
This package is provided "as is" and without any express or
|
@@ -0,0 +1,18 @@
|
|
1
|
+
base = File.basename(Dir.pwd)
|
2
|
+
|
3
|
+
if base == "examples" || base =~ /net-pingsimple.*/
|
4
|
+
Dir.chdir("..") if base == "examples"
|
5
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
require "net/ping"
|
9
|
+
include Net
|
10
|
+
|
11
|
+
good = "www.rubyforge.org"
|
12
|
+
bad = "foo.bar.baz"
|
13
|
+
|
14
|
+
pe = PingExternal.new(good)
|
15
|
+
p pe.ping?
|
16
|
+
|
17
|
+
pe = PingExternal.new(bad)
|
18
|
+
p pe.ping?
|
@@ -0,0 +1,19 @@
|
|
1
|
+
base = File.basename(Dir.pwd)
|
2
|
+
|
3
|
+
if base == "examples" || base =~ /net-pingsimple.*/
|
4
|
+
Dir.chdir("..") if base == "examples"
|
5
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
require "net/ping"
|
9
|
+
include Net
|
10
|
+
|
11
|
+
good = "http://www.pragmaticprogrammer.com/index.html"
|
12
|
+
bad = "http://www.ruby-lang.org/index.html"
|
13
|
+
|
14
|
+
hp = PingHTTP.new(good)
|
15
|
+
p hp.ping?
|
16
|
+
|
17
|
+
hp = PingHTTP.new(bad)
|
18
|
+
p hp.ping?
|
19
|
+
p hp.exception
|
@@ -0,0 +1,22 @@
|
|
1
|
+
base = File.basename(Dir.pwd)
|
2
|
+
|
3
|
+
if base == "examples" || base =~ /net-pingsimple.*/
|
4
|
+
Dir.chdir("..") if base == "examples"
|
5
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
host = "www.ruby-lang.org"
|
9
|
+
|
10
|
+
require "net/ping"
|
11
|
+
include Net
|
12
|
+
|
13
|
+
good = "www.rubyforge.org"
|
14
|
+
bad = "foo.bar.baz"
|
15
|
+
|
16
|
+
PingTCP.ecr = true
|
17
|
+
|
18
|
+
pe = PingTCP.new(good,"http")
|
19
|
+
p pe.ping?
|
20
|
+
|
21
|
+
pe = PingTCP.new(bad)
|
22
|
+
p pe.ping?
|
@@ -0,0 +1,15 @@
|
|
1
|
+
base = File.basename(Dir.pwd)
|
2
|
+
|
3
|
+
if base == "examples" || base =~ /net-pingsimple.*/
|
4
|
+
Dir.chdir("..") if base == "examples"
|
5
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
require "net/ping"
|
9
|
+
include Net
|
10
|
+
|
11
|
+
host = "www.ruby-lang.org"
|
12
|
+
u = PingUDP.new(host)
|
13
|
+
p u.ping?
|
14
|
+
|
15
|
+
puts "Done"
|
data/lib/net/ping/external.rb
CHANGED
@@ -46,6 +46,7 @@ module Net
|
|
46
46
|
|
47
47
|
begin
|
48
48
|
e = nil
|
49
|
+
|
49
50
|
Timeout.timeout(@timeout){
|
50
51
|
input, output, error = Open3.popen3(pstring)
|
51
52
|
e = error.gets # Can't chomp yet, might be nil
|
@@ -90,6 +91,10 @@ module Net
|
|
90
91
|
end
|
91
92
|
rescue Exception => err
|
92
93
|
@exception = err.message
|
94
|
+
ensure
|
95
|
+
input.close if input && !input.closed?
|
96
|
+
error.close if error && !error.closed?
|
97
|
+
output.close if output && !output.closed?
|
93
98
|
end
|
94
99
|
|
95
100
|
# There is no duration if the ping failed
|
data/lib/net/ping/icmp.rb
CHANGED
data/lib/net/ping/ping.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'timeout'
|
3
3
|
|
4
|
+
# The Net module serves as a namespace only.
|
5
|
+
#
|
4
6
|
module Net
|
7
|
+
|
8
|
+
# The Ping class serves as an abstract base class for all other Ping class
|
9
|
+
# types. You should not instantiate this class directly.
|
10
|
+
#
|
5
11
|
class Ping
|
6
|
-
VERSION = '1.
|
12
|
+
VERSION = '1.3.0'
|
7
13
|
|
8
14
|
# The host to ping. In the case of Ping::HTTP, this is the URI.
|
9
15
|
attr_accessor :host
|
data/lib/net/ping/wmi.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
|
+
require 'ping'
|
3
|
+
require 'win32ole'
|
4
|
+
|
5
|
+
# The Net module serves as a namespace only.
|
6
|
+
#
|
7
|
+
module Net
|
8
|
+
|
9
|
+
# The Ping::WMI class encapsulates the Win32_PingStatus WMI class for
|
10
|
+
# MS Windows.
|
11
|
+
#
|
12
|
+
class Ping::WMI < Ping
|
13
|
+
|
14
|
+
PingStatus = Struct.new(
|
15
|
+
'PingStatus',
|
16
|
+
:address,
|
17
|
+
:buffer_size,
|
18
|
+
:no_fragmentation,
|
19
|
+
:primary_address_resolution_status,
|
20
|
+
:protocol_address,
|
21
|
+
:protocol_address_resolved,
|
22
|
+
:record_route,
|
23
|
+
:reply_inconsistency,
|
24
|
+
:reply_size,
|
25
|
+
:resolve_address_names,
|
26
|
+
:response_time,
|
27
|
+
:response_time_to_live,
|
28
|
+
:route_record,
|
29
|
+
:route_record_resolved,
|
30
|
+
:source_route,
|
31
|
+
:source_route_type,
|
32
|
+
:status_code,
|
33
|
+
:timeout,
|
34
|
+
:timestamp_record,
|
35
|
+
:timestamp_record_address,
|
36
|
+
:timestamp_record_address_resolved,
|
37
|
+
:timestamp_route,
|
38
|
+
:time_to_live,
|
39
|
+
:type_of_service
|
40
|
+
)
|
41
|
+
|
42
|
+
# Unlike the ping method for other Ping subclasses, this version returns
|
43
|
+
# a PingStatus struct which contains various bits of information about
|
44
|
+
# the results of the ping itself, such as response time.
|
45
|
+
#
|
46
|
+
# In addition, this version allows you to pass certain options that are
|
47
|
+
# then passed on to the underlying WQL query. See the MSDN documentation
|
48
|
+
# on Win32_PingStatus for details.
|
49
|
+
#
|
50
|
+
# Examples:
|
51
|
+
#
|
52
|
+
# # Ping with no options
|
53
|
+
# Ping::WMI.ping('www.perl.com')
|
54
|
+
#
|
55
|
+
# # Ping with options
|
56
|
+
# Ping::WMI.ping('www.perl.com', :BufferSize => 64, :NoFragmentation => true)
|
57
|
+
#--
|
58
|
+
# The PingStatus struct is a wrapper for the Win32_PingStatus WMI class.
|
59
|
+
#
|
60
|
+
def ping(host = @host, options = {})
|
61
|
+
super(host)
|
62
|
+
|
63
|
+
lhost = Socket.gethostname
|
64
|
+
|
65
|
+
cs = "winmgmts:{impersonationLevel=impersonate}!//#{lhost}/root/cimv2"
|
66
|
+
wmi = WIN32OLE.connect(cs)
|
67
|
+
|
68
|
+
query = "select * from win32_pingstatus where address = '#{host}'"
|
69
|
+
|
70
|
+
unless options.empty?
|
71
|
+
options.each{ |key, value|
|
72
|
+
if value.is_a?(String)
|
73
|
+
query << " and #{key} = '#{value}'"
|
74
|
+
else
|
75
|
+
query << " and #{key} = #{value}"
|
76
|
+
end
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
status = Struct::PingStatus.new
|
81
|
+
|
82
|
+
wmi.execquery(query).each{ |obj|
|
83
|
+
status.address = obj.Address
|
84
|
+
status.buffer_size = obj.BufferSize
|
85
|
+
status.no_fragmentation = obj.NoFragmentation
|
86
|
+
status.primary_address_resolution_status = obj.PrimaryAddressResolutionStatus
|
87
|
+
status.protocol_address = obj.ProtocolAddress
|
88
|
+
status.protocol_address_resolved = obj.ProtocolAddressResolved
|
89
|
+
status.record_route = obj.RecordRoute
|
90
|
+
status.reply_inconsistency = obj.ReplyInconsistency
|
91
|
+
status.reply_size = obj.ReplySize
|
92
|
+
status.resolve_address_names = obj.ResolveAddressNames
|
93
|
+
status.response_time = obj.ResponseTime
|
94
|
+
status.response_time_to_live = obj.ResponseTimeToLive
|
95
|
+
status.route_record = obj.RouteRecord
|
96
|
+
status.route_record_resolved = obj.RouteRecordResolved
|
97
|
+
status.source_route = obj.SourceRoute
|
98
|
+
status.source_route_type = obj.SourceRouteType
|
99
|
+
status.status_code = obj.StatusCode
|
100
|
+
status.timeout = obj.Timeout
|
101
|
+
status.timestamp_record = obj.TimeStampRecord
|
102
|
+
status.timestamp_record_address = obj.TimeStampRecordAddress
|
103
|
+
status.timestamp_record_address_resolved = obj.TimeStampRecordAddressResolved
|
104
|
+
status.timestamp_route = obj.TimeStampRoute
|
105
|
+
status.time_to_live = obj.TimeToLive
|
106
|
+
status.type_of_service = obj.TypeOfService
|
107
|
+
}
|
108
|
+
|
109
|
+
status
|
110
|
+
end
|
111
|
+
|
112
|
+
# Unlike Net::Ping::WMI#ping, this method returns true or false to
|
113
|
+
# indicate whether or not the ping was successful.
|
114
|
+
#
|
115
|
+
def ping?(host = @host, options = {})
|
116
|
+
ping(host, options).status_code == 0
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/net-ping.gemspec
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
|
-
gem.name
|
5
|
-
gem.version
|
6
|
-
gem.author
|
7
|
-
gem.email
|
8
|
-
gem.homepage
|
9
|
-
gem.summary
|
10
|
-
gem.test_file
|
11
|
-
gem.has_rdoc
|
12
|
-
gem.rubyforge_project =
|
13
|
-
gem.files
|
14
|
-
gem.
|
15
|
-
|
16
|
-
gem.extra_rdoc_files = ["README", "CHANGES", "doc/ping.txt"]
|
4
|
+
gem.name = 'net-ping'
|
5
|
+
gem.version = '1.3.0'
|
6
|
+
gem.author = 'Daniel J. Berger'
|
7
|
+
gem.email = 'djberg96@gmail.com'
|
8
|
+
gem.homepage = 'http://www.rubyforge.org/projects/shards'
|
9
|
+
gem.summary = 'A ping interface for Ruby.'
|
10
|
+
gem.test_file = 'test/test_net_ping.rb'
|
11
|
+
gem.has_rdoc = true
|
12
|
+
gem.rubyforge_project = 'shards'
|
13
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
14
|
+
gem.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
|
15
|
+
|
17
16
|
gem.add_dependency('test-unit', '>= 2.0.2')
|
18
17
|
|
19
18
|
case RUBY_PLATFORM
|
@@ -25,12 +24,12 @@ spec = Gem::Specification.new do |gem|
|
|
25
24
|
gem.platform = Gem::Platform::RUBY
|
26
25
|
end
|
27
26
|
|
28
|
-
description =
|
29
|
-
description <<
|
27
|
+
description = 'A ping interface for Ruby. Includes TCP, HTTP, ICMP, UDP, '
|
28
|
+
description << 'External, and WMI ping interfaces.'
|
30
29
|
gem.description = description
|
31
30
|
end
|
32
31
|
|
33
|
-
if $
|
34
|
-
Gem.manage_gems if Gem::RubyGemsVersion.to_f
|
32
|
+
if $PROGRAM_NAME == __FILE__
|
33
|
+
Gem.manage_gems if Gem::RubyGemsVersion.to_f < 1.0
|
35
34
|
Gem::Builder.new(spec).build
|
36
35
|
end
|
data/test/test_net_ping_http.rb
CHANGED
data/test/test_net_ping_icmp.rb
CHANGED
@@ -17,17 +17,24 @@ unless Process.euid == 0
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class TC_PingICMP < Test::Unit::TestCase
|
20
|
+
def self.startup
|
21
|
+
@@one_click = Config::CONFIG['host_os'] == 'mswin32'
|
22
|
+
end
|
23
|
+
|
20
24
|
def setup
|
21
25
|
@host = "www.ruby-lang.org"
|
22
26
|
@icmp = Ping::ICMP.new(@host)
|
23
27
|
end
|
24
28
|
|
25
29
|
def test_version
|
26
|
-
assert_equal('1.
|
30
|
+
assert_equal('1.3.0', PingICMP::VERSION)
|
27
31
|
end
|
28
32
|
|
29
33
|
def test_ping
|
30
34
|
assert_respond_to(@icmp, :ping)
|
35
|
+
|
36
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
37
|
+
|
31
38
|
assert_nothing_raised{ @icmp.ping }
|
32
39
|
assert_nothing_raised{ @icmp.ping(@host) }
|
33
40
|
end
|
@@ -35,27 +42,34 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
35
42
|
def test_ping_aliases_basic
|
36
43
|
assert_respond_to(@icmp, :ping?)
|
37
44
|
assert_respond_to(@icmp, :pingecho)
|
45
|
+
|
46
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
47
|
+
|
38
48
|
assert_nothing_raised{ @icmp.ping? }
|
39
49
|
assert_nothing_raised{ @icmp.ping?(@host) }
|
40
50
|
end
|
41
51
|
|
42
52
|
def test_ping_returns_boolean
|
53
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
43
54
|
assert_boolean(@icmp.pingecho)
|
44
55
|
assert_boolean(@icmp.pingecho(@host))
|
45
56
|
end
|
46
57
|
|
47
58
|
def test_ping_expected_failure
|
59
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
48
60
|
assert_false(Ping::ICMP.new('bogus').ping?)
|
49
61
|
assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
50
62
|
end
|
51
63
|
|
52
64
|
def test_bind
|
65
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
53
66
|
assert_respond_to(@icmp, :bind)
|
54
67
|
assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
|
55
68
|
assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
|
56
69
|
end
|
57
70
|
|
58
71
|
def test_duration
|
72
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
59
73
|
assert_nothing_raised{ @icmp.ping }
|
60
74
|
assert_respond_to(@icmp, :duration)
|
61
75
|
assert_kind_of(Float, @icmp.duration)
|
@@ -80,6 +94,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
80
94
|
|
81
95
|
def test_exception
|
82
96
|
assert_respond_to(@icmp, :exception)
|
97
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
83
98
|
assert_nothing_raised{ @icmp.ping }
|
84
99
|
assert_nil(@icmp.exception)
|
85
100
|
end
|
@@ -100,6 +115,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
100
115
|
|
101
116
|
def test_odd_data_size_ok
|
102
117
|
assert_nothing_raised{ @icmp.data_size = 57 }
|
118
|
+
omit_if(@@one_click, 'Unreliable socket library')
|
103
119
|
assert_boolean(@icmp.ping)
|
104
120
|
end
|
105
121
|
|
@@ -107,4 +123,8 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
107
123
|
@host = nil
|
108
124
|
@icmp = nil
|
109
125
|
end
|
126
|
+
|
127
|
+
def self.shutdown
|
128
|
+
@@one_click = nil
|
129
|
+
end
|
110
130
|
end
|
data/test/test_net_ping_tcp.rb
CHANGED
@@ -13,12 +13,13 @@ include Net
|
|
13
13
|
|
14
14
|
class TC_PingTCP < Test::Unit::TestCase
|
15
15
|
def setup
|
16
|
-
@host =
|
17
|
-
@
|
16
|
+
@host = 'www.ruby-lang.org'
|
17
|
+
@port = 'ftp'
|
18
|
+
@tcp = Ping::TCP.new(@host, @port)
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_version
|
21
|
-
assert_equal('1.
|
22
|
+
assert_equal('1.3.0', PingTCP::VERSION)
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_ping
|
@@ -38,7 +39,8 @@ class TC_PingTCP < Test::Unit::TestCase
|
|
38
39
|
|
39
40
|
def test_ping_service_check_false
|
40
41
|
msg = "+this test may fail depending on your network environment+"
|
41
|
-
|
42
|
+
Ping::TCP.service_check = false
|
43
|
+
@tcp = Ping::TCP.new('localhost')
|
42
44
|
assert_equal(false, @tcp.ping?, msg)
|
43
45
|
assert_equal(false, @tcp.exception.nil?, "Bad exception data")
|
44
46
|
end
|
@@ -54,7 +56,7 @@ class TC_PingTCP < Test::Unit::TestCase
|
|
54
56
|
assert_respond_to(PingTCP, :service_check=)
|
55
57
|
end
|
56
58
|
|
57
|
-
# These will be removed
|
59
|
+
# These will be removed eventually
|
58
60
|
def test_service_check_aliases
|
59
61
|
assert_respond_to(PingTCP, :econnrefused)
|
60
62
|
assert_respond_to(PingTCP, :econnrefused=)
|
@@ -66,10 +68,12 @@ class TC_PingTCP < Test::Unit::TestCase
|
|
66
68
|
assert_raises(ArgumentError){ PingTCP.service_check = "blah" }
|
67
69
|
end
|
68
70
|
|
71
|
+
# If the ping failed, the duration will be nil
|
69
72
|
def test_duration
|
70
73
|
assert_nothing_raised{ @tcp.ping }
|
71
74
|
assert_respond_to(@tcp, :duration)
|
72
|
-
|
75
|
+
omit_if(@tcp.duration.nil?, 'ping failed, skipping')
|
76
|
+
assert_kind_of(Float, @tcp.duration)
|
73
77
|
end
|
74
78
|
|
75
79
|
def test_host
|
@@ -81,7 +85,7 @@ class TC_PingTCP < Test::Unit::TestCase
|
|
81
85
|
def test_port
|
82
86
|
assert_respond_to(@tcp, :port)
|
83
87
|
assert_respond_to(@tcp, :port=)
|
84
|
-
assert_equal(
|
88
|
+
assert_equal('ftp', @tcp.port)
|
85
89
|
end
|
86
90
|
|
87
91
|
def test_timeout
|
data/test/test_net_ping_udp.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# test_net_ping_wmi.rb
|
3
|
+
#
|
4
|
+
# Test case for the Net::Ping::WMI class. These tests will only be
|
5
|
+
# run MS Windows. You should run this test via the 'test' or
|
6
|
+
# 'test_wmi' Rake task.
|
7
|
+
#######################################################################
|
8
|
+
require 'rubygems'
|
9
|
+
gem 'test-unit'
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
require 'net/ping/wmi'
|
13
|
+
include Net
|
14
|
+
|
15
|
+
class TC_Ping_WMI < Test::Unit::TestCase
|
16
|
+
def self.startup
|
17
|
+
@@windows = Config::CONFIG['host_os'] =~ /mswin|cygwin|mingw/i
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@host = "www.ruby-lang.org"
|
22
|
+
@wmi = Ping::WMI.new(@host) if @@windows
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_version
|
26
|
+
assert_equal('1.3.0', Ping::WMI::VERSION)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_ping_basic
|
30
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
31
|
+
assert_respond_to(@wmi, :ping)
|
32
|
+
assert_nothing_raised{ @wmi.ping }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_ping_with_host
|
36
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
37
|
+
assert_nothing_raised{ @wmi.ping(@host) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_ping_with_options
|
41
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
42
|
+
assert_nothing_raised{ @wmi.ping(@host, :NoFragmentation => true) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_pingecho_alias
|
46
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
47
|
+
assert_respond_to(@wmi, :pingecho)
|
48
|
+
assert_nothing_raised{ @wmi.pingecho }
|
49
|
+
assert_nothing_raised{ @wmi.pingecho(@host) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_ping_returns_struct
|
53
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
54
|
+
assert_kind_of(Struct::PingStatus, @wmi.ping)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_ping_returns_boolean
|
58
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
59
|
+
assert_boolean(@wmi.ping?)
|
60
|
+
assert_boolean(@wmi.ping?(@host))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_ping_expected_failure
|
64
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
65
|
+
assert_false(Ping::WMI.new('bogus').ping?)
|
66
|
+
assert_false(Ping::WMI.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_exception
|
70
|
+
omit_unless(@@windows, 'skipped on Unix platforms')
|
71
|
+
assert_respond_to(@wmi, :exception)
|
72
|
+
assert_nothing_raised{ @wmi.ping }
|
73
|
+
assert_nil(@wmi.exception)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_warning
|
77
|
+
assert_respond_to(@wmi, :warning)
|
78
|
+
end
|
79
|
+
|
80
|
+
def teardown
|
81
|
+
@host = nil
|
82
|
+
@wmi = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.shutdown
|
86
|
+
@@windows = nil
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-19 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.2.7
|
44
44
|
version:
|
45
|
-
description: A ping interface for Ruby. Includes TCP, HTTP, ICMP, UDP, and
|
45
|
+
description: A ping interface for Ruby. Includes TCP, HTTP, ICMP, UDP, External, and WMI ping interfaces.
|
46
46
|
email: djberg96@gmail.com
|
47
47
|
executables: []
|
48
48
|
|
@@ -53,32 +53,35 @@ extra_rdoc_files:
|
|
53
53
|
- CHANGES
|
54
54
|
- doc/ping.txt
|
55
55
|
files:
|
56
|
-
- lib/net/ping
|
57
|
-
- lib/net/ping.rb
|
58
56
|
- CHANGES
|
59
|
-
- doc
|
60
|
-
- examples
|
61
|
-
-
|
57
|
+
- doc/ping.txt
|
58
|
+
- examples/test_pingexternal.rb
|
59
|
+
- examples/test_pinghttp.rb
|
60
|
+
- examples/test_pingtcp.rb
|
61
|
+
- examples/test_pingudp.rb
|
62
|
+
- lib/net/ping/external.rb
|
63
|
+
- lib/net/ping/http.rb
|
64
|
+
- lib/net/ping/icmp.rb
|
65
|
+
- lib/net/ping/ping.rb
|
66
|
+
- lib/net/ping/tcp.rb
|
67
|
+
- lib/net/ping/udp.rb
|
68
|
+
- lib/net/ping/wmi.rb
|
69
|
+
- lib/net/ping.rb
|
62
70
|
- MANIFEST
|
63
71
|
- net-ping.gemspec
|
64
72
|
- Rakefile
|
65
73
|
- README
|
66
|
-
- test
|
67
74
|
- test/test_net_ping.rb
|
68
75
|
- test/test_net_ping_external.rb
|
69
76
|
- test/test_net_ping_http.rb
|
70
77
|
- test/test_net_ping_icmp.rb
|
71
78
|
- test/test_net_ping_tcp.rb
|
72
79
|
- test/test_net_ping_udp.rb
|
73
|
-
-
|
74
|
-
- lib/net/ping/http.rb
|
75
|
-
- lib/net/ping/icmp.rb
|
76
|
-
- lib/net/ping/ping.rb
|
77
|
-
- lib/net/ping/tcp.rb
|
78
|
-
- lib/net/ping/udp.rb
|
79
|
-
- doc/ping.txt
|
80
|
+
- test/test_net_ping_wmi.rb
|
80
81
|
has_rdoc: true
|
81
82
|
homepage: http://www.rubyforge.org/projects/shards
|
83
|
+
licenses: []
|
84
|
+
|
82
85
|
post_install_message:
|
83
86
|
rdoc_options: []
|
84
87
|
|
@@ -99,9 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
102
|
requirements: []
|
100
103
|
|
101
104
|
rubyforge_project: shards
|
102
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.3
|
103
106
|
signing_key:
|
104
|
-
specification_version:
|
107
|
+
specification_version: 3
|
105
108
|
summary: A ping interface for Ruby.
|
106
109
|
test_files:
|
107
110
|
- test/test_net_ping.rb
|