net-ping 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +11 -0
- data/README +6 -6
- data/doc/ping.txt +2 -2
- data/lib/net/ping/external.rb +32 -20
- data/lib/net/ping/icmp.rb +33 -34
- data/lib/net/ping/ping.rb +1 -1
- data/net-ping.gemspec +2 -3
- data/test/test_net_ping.rb +1 -1
- data/test/test_net_ping_external.rb +9 -0
- data/test/test_net_ping_icmp.rb +49 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a4aeabebdb1bf7c3347538c1ad96428e5d7386
|
4
|
+
data.tar.gz: 6434d02460e9ff981db346adde0664029a7e0de0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8075c1a265cd6d0e911e5e4a6a2e38d377d0c00d5a76c05cee37e089f40a51a7405051280e299ba168e8db7854387dd49a334fcc6c12f98cfc17cdebd91b26a
|
7
|
+
data.tar.gz: 8a450d951dafecd0133a85c16f01568c39c6ec6dbea07760b149d9b8f27dfc5de957e3fc4ffb950b1b49328b490377b123e3c031b82faf8f99f3aa74a541fce7
|
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.7.3 - 3-Apr-2014
|
2
|
+
* Removed the Timeout block for the Ping::External class as it apparently
|
3
|
+
hasn't worked with open3 for some time. Instead, it now uses your command
|
4
|
+
line ping's timeout switch. Thanks go to Andrea Bernardo Ciddio for the
|
5
|
+
spot.
|
6
|
+
* Made ICMP pings thread safe. I think.
|
7
|
+
* Removed a redundant Timeout block in the Ping::ICMP class.
|
8
|
+
* If an ICMP ping times out, the exception attribute is set to "timeout".
|
9
|
+
* Added explicit support for AIX for the Ping::External class.
|
10
|
+
* Bumped minimum required Ruby version to 1.9.3.
|
11
|
+
|
1
12
|
== 1.7.2 - 21-Jan-2014
|
2
13
|
* Fixed a bug in the Ping::HTTP constructor where it was not honoring the
|
3
14
|
port if provided as the second argument. Thanks go to Florian Anderiasch
|
data/README
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
* fakeweb (test only)
|
8
8
|
* test-unit (test only)
|
9
9
|
|
10
|
+
Ruby users should use Ruby 1.9.3 or later.
|
10
11
|
JRuby users should use JRuby 1.6.7 or later.
|
11
12
|
|
12
13
|
== Installation
|
@@ -17,10 +18,6 @@
|
|
17
18
|
attention to the documentation pertaining to ECONNREFUSED and TCP pings.
|
18
19
|
|
19
20
|
Also note the documentation regarding down hosts.
|
20
|
-
|
21
|
-
You do not need win32-open3 with Ruby 1.9.x. The open3 library that ships
|
22
|
-
as part of the Ruby standard library should work.
|
23
|
-
|
24
21
|
== How to require net-ping
|
25
22
|
You can do either this:
|
26
23
|
|
@@ -44,8 +41,8 @@
|
|
44
41
|
JRuby 1.6.7 or later is required for external pings because of a bug
|
45
42
|
in earlier versions with open3 and stream handling.
|
46
43
|
|
47
|
-
ICMP pings
|
48
|
-
|
44
|
+
ICMP pings will not work with JRuby without some sort of third-party
|
45
|
+
library support for raw sockets in Java, such as RockSaw.
|
49
46
|
|
50
47
|
== License
|
51
48
|
Artistic 2.0
|
@@ -60,3 +57,6 @@
|
|
60
57
|
If you installed this library via Rubygems, you can view the inline
|
61
58
|
documentation via ri or fire up 'gem server', and point your browser at
|
62
59
|
http://localhost:8808.
|
60
|
+
|
61
|
+
== Author
|
62
|
+
Daniel J. Berger
|
data/doc/ping.txt
CHANGED
@@ -221,7 +221,7 @@ Ping#warning
|
|
221
221
|
UDP pings may not work with older versions of Ruby 1.9.x.
|
222
222
|
|
223
223
|
Please report any bugs on the project page at
|
224
|
-
|
224
|
+
https://github.com/djberg96/net-ping
|
225
225
|
|
226
226
|
= Acknowledgements
|
227
227
|
The Ping::ICMP#ping method is based largely on the identical method from
|
@@ -235,7 +235,7 @@ Ping#warning
|
|
235
235
|
Artistic 2.0
|
236
236
|
|
237
237
|
= Copyright
|
238
|
-
(C) 2003-
|
238
|
+
(C) 2003-2014 Daniel J. Berger, All Rights Reserved
|
239
239
|
|
240
240
|
= Warranty
|
241
241
|
This package is provided "as is" and without any express or
|
data/lib/net/ping/external.rb
CHANGED
@@ -22,14 +22,18 @@ module Net
|
|
22
22
|
bool = false
|
23
23
|
|
24
24
|
case RbConfig::CONFIG['host_os']
|
25
|
-
when /linux
|
26
|
-
pcmd += ['-
|
25
|
+
when /linux/i
|
26
|
+
pcmd += ['-c', '1', '-W', @timeout.to_s, host]
|
27
|
+
when /aix/i
|
28
|
+
pcmd += ['-c', '1', '-w', @timeout.to_s, host]
|
29
|
+
when /bsd|osx|mach|darwin/i
|
30
|
+
pcmd += ['-c', '1', '-t', @timeout.to_s, host]
|
27
31
|
when /solaris|sunos/i
|
28
|
-
pcmd += [host,
|
32
|
+
pcmd += [host, @timeout.to_s]
|
29
33
|
when /hpux/i
|
30
|
-
pcmd += [host, '-n1']
|
34
|
+
pcmd += [host, '-n1', '-m', @timeout.to_s]
|
31
35
|
when /win32|windows|msdos|mswin|cygwin|mingw/i
|
32
|
-
pcmd += ['-n', '1', host]
|
36
|
+
pcmd += ['-n', '1', '-w', (@timeout * 1000).to_s, host]
|
33
37
|
else
|
34
38
|
pcmd += [host]
|
35
39
|
end
|
@@ -39,25 +43,33 @@ module Net
|
|
39
43
|
begin
|
40
44
|
err = nil
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
Open3.popen3(*pcmd) do |stdin, stdout, stderr, thread|
|
47
|
+
stdin.close
|
48
|
+
err = stderr.gets # Can't chomp yet, might be nil
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
case thread.value.exitstatus
|
51
|
+
when 0
|
52
|
+
bool = true # Success, at least one response.
|
53
|
+
if err & err =~ /warning/i
|
54
|
+
@warning = err.chomp
|
55
|
+
end
|
56
|
+
when 2
|
57
|
+
bool = false # Transmission successful, no response.
|
58
|
+
@exception = err.chomp if err
|
59
|
+
else
|
60
|
+
bool = false # An error occurred
|
61
|
+
if err
|
54
62
|
@exception = err.chomp
|
55
63
|
else
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
stdout.each_line do |line|
|
65
|
+
if line =~ /(timed out|could not find host|packet loss)/i
|
66
|
+
@exception = line.chomp
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
59
71
|
end
|
60
|
-
|
72
|
+
end
|
61
73
|
rescue Exception => error
|
62
74
|
@exception = error.message
|
63
75
|
end
|
data/lib/net/ping/icmp.rb
CHANGED
@@ -44,7 +44,7 @@ module Net
|
|
44
44
|
|
45
45
|
0.upto(@data_size){ |n| @data << (n % 256).chr }
|
46
46
|
|
47
|
-
@
|
47
|
+
@ping_id = (Thread.current.object_id ^ Process.pid) & 0xffff
|
48
48
|
|
49
49
|
super(host, port, timeout)
|
50
50
|
@port = nil # This value is not used in ICMP pings.
|
@@ -59,7 +59,7 @@ module Net
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# Associates the local end of the socket connection with the given
|
62
|
-
# +host+ and +port+.
|
62
|
+
# +host+ and +port+. The default port is 0.
|
63
63
|
#
|
64
64
|
def bind(host, port = 0)
|
65
65
|
@bind_host = host
|
@@ -90,10 +90,10 @@ module Net
|
|
90
90
|
timeout = @timeout
|
91
91
|
|
92
92
|
checksum = 0
|
93
|
-
msg = [ICMP_ECHO, ICMP_SUBCODE, checksum, @
|
93
|
+
msg = [ICMP_ECHO, ICMP_SUBCODE, checksum, @ping_id, @seq, @data].pack(pstring)
|
94
94
|
|
95
95
|
checksum = checksum(msg)
|
96
|
-
msg = [ICMP_ECHO, ICMP_SUBCODE, checksum, @
|
96
|
+
msg = [ICMP_ECHO, ICMP_SUBCODE, checksum, @ping_id, @seq, @data].pack(pstring)
|
97
97
|
|
98
98
|
begin
|
99
99
|
saddr = Socket.pack_sockaddr_in(0, host)
|
@@ -107,37 +107,36 @@ module Net
|
|
107
107
|
socket.send(msg, 0, saddr) # Send the message
|
108
108
|
|
109
109
|
begin
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
if io_array.nil?
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
if pid == @pid && seq == @seq && type == ICMP_ECHOREPLY
|
136
|
-
bool = true
|
137
|
-
break
|
138
|
-
end
|
110
|
+
while true
|
111
|
+
io_array = select([socket], nil, nil, timeout)
|
112
|
+
|
113
|
+
if io_array.nil? || io_array[0].empty?
|
114
|
+
@exception = "timeout" if io_array.nil?
|
115
|
+
return false
|
116
|
+
end
|
117
|
+
|
118
|
+
ping_id = nil
|
119
|
+
seq = nil
|
120
|
+
|
121
|
+
data = socket.recvfrom(1500).first
|
122
|
+
type = data[20, 2].unpack('C2').first
|
123
|
+
|
124
|
+
case type
|
125
|
+
when ICMP_ECHOREPLY
|
126
|
+
if data.length >= 28
|
127
|
+
ping_id, seq = data[24, 4].unpack('n3')
|
128
|
+
end
|
129
|
+
else
|
130
|
+
if data.length > 56
|
131
|
+
ping_id, seq = data[52, 4].unpack('n3')
|
132
|
+
end
|
139
133
|
end
|
140
|
-
|
134
|
+
|
135
|
+
if ping_id == @ping_id && seq == @seq && type == ICMP_ECHOREPLY
|
136
|
+
bool = true
|
137
|
+
break
|
138
|
+
end
|
139
|
+
end
|
141
140
|
rescue Exception => err
|
142
141
|
@exception = err
|
143
142
|
ensure
|
data/lib/net/ping/ping.rb
CHANGED
data/net-ping.gemspec
CHANGED
@@ -3,7 +3,7 @@ require 'rbconfig'
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'net-ping'
|
6
|
-
spec.version = '1.7.
|
6
|
+
spec.version = '1.7.3'
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.author = 'Daniel J. Berger'
|
9
9
|
spec.email = 'djberg96@gmail.com'
|
@@ -12,11 +12,10 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.test_file = 'test/test_net_ping.rb'
|
13
13
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
14
|
|
15
|
-
spec.rubyforge_project = 'shards'
|
16
15
|
spec.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
|
17
16
|
|
18
17
|
# The TCP Ping class requires this for non-blocking sockets.
|
19
|
-
spec.required_ruby_version = ">= 1.9.
|
18
|
+
spec.required_ruby_version = ">= 1.9.3"
|
20
19
|
|
21
20
|
spec.add_development_dependency('test-unit')
|
22
21
|
spec.add_development_dependency('fakeweb')
|
data/test/test_net_ping.rb
CHANGED
@@ -120,6 +120,15 @@ class TC_Net_Ping_External < Test::Unit::TestCase
|
|
120
120
|
assert_nil(@pe.warning)
|
121
121
|
end
|
122
122
|
|
123
|
+
test "timing out causes expected result" do
|
124
|
+
ext = Net::Ping::External.new('foo.bar.baz', nil, 1)
|
125
|
+
start = Time.now
|
126
|
+
assert_false(ext.ping?)
|
127
|
+
elapsed = Time.now - start
|
128
|
+
assert_true(elapsed < 2.5, "Actual elapsed: #{elapsed}")
|
129
|
+
assert_not_nil(ext.exception)
|
130
|
+
end
|
131
|
+
|
123
132
|
def teardown
|
124
133
|
@host = nil
|
125
134
|
@bogus = nil
|
data/test/test_net_ping_icmp.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#######################################################################
|
2
2
|
# test_net_ping_icmp.rb
|
3
3
|
#
|
4
|
-
# Test case for the Net::PingICMP class.
|
4
|
+
# Test case for the Net::PingICMP class. You must run this test case
|
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
8
|
require 'test-unit'
|
9
9
|
require 'net/ping/icmp'
|
10
|
+
require 'thread'
|
10
11
|
|
11
12
|
if File::ALT_SEPARATOR
|
12
13
|
require 'win32/security'
|
@@ -21,30 +22,62 @@ else
|
|
21
22
|
end
|
22
23
|
|
23
24
|
class TC_PingICMP < Test::Unit::TestCase
|
25
|
+
def self.startup
|
26
|
+
@@jruby = RUBY_PLATFORM == 'java'
|
27
|
+
end
|
28
|
+
|
24
29
|
def setup
|
25
30
|
@host = '127.0.0.1' # 'localhost'
|
26
31
|
@icmp = Net::Ping::ICMP.new(@host)
|
32
|
+
@concurrency = 3
|
27
33
|
end
|
28
34
|
|
29
35
|
test "icmp ping basic functionality" do
|
30
36
|
assert_respond_to(@icmp, :ping)
|
37
|
+
omit_if(@@jruby)
|
31
38
|
assert_nothing_raised{ @icmp.ping }
|
32
39
|
end
|
33
40
|
|
34
41
|
test "icmp ping accepts a host" do
|
42
|
+
omit_if(@@jruby)
|
35
43
|
assert_nothing_raised{ @icmp.ping(@host) }
|
36
44
|
end
|
37
45
|
|
38
46
|
test "icmp ping returns a boolean" do
|
47
|
+
omit_if(@@jruby)
|
39
48
|
assert_boolean(@icmp.ping)
|
40
49
|
assert_boolean(@icmp.ping(@host))
|
41
50
|
end
|
42
51
|
|
43
52
|
test "icmp ping of local host is successful" do
|
53
|
+
omit_if(@@jruby)
|
44
54
|
assert_true(Net::Ping::ICMP.new(@host).ping?)
|
45
55
|
assert_true(Net::Ping::ICMP.new('192.168.0.1').ping?)
|
46
56
|
end
|
47
57
|
|
58
|
+
test "threaded icmp ping returns expected results" do
|
59
|
+
omit_if(@@jruby)
|
60
|
+
ips = ['8.8.4.4', '8.8.9.9', '127.0.0.1', '8.8.8.8', '8.8.8.9']
|
61
|
+
queue = Queue.new
|
62
|
+
threads = []
|
63
|
+
|
64
|
+
ips.each{ |ip| queue << ip }
|
65
|
+
|
66
|
+
@concurrency.times{
|
67
|
+
threads << Thread.new(queue) do |q|
|
68
|
+
ip = q.pop
|
69
|
+
icmp = Net::Ping::ICMP.new(ip, nil, 1)
|
70
|
+
if ip =~ /9/
|
71
|
+
assert_false(icmp.ping?)
|
72
|
+
else
|
73
|
+
assert_true(icmp.ping?)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
78
|
+
threads.each{ |t| t.join }
|
79
|
+
end
|
80
|
+
|
48
81
|
test "ping? is an alias for ping" do
|
49
82
|
assert_respond_to(@icmp, :ping?)
|
50
83
|
assert_alias_method(@icmp, :ping?, :ping)
|
@@ -56,6 +89,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
56
89
|
end
|
57
90
|
|
58
91
|
test "icmp ping fails if host is invalid" do
|
92
|
+
omit_if(@@jruby)
|
59
93
|
assert_false(Net::Ping::ICMP.new('bogus').ping?)
|
60
94
|
assert_false(Net::Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
61
95
|
end
|
@@ -67,6 +101,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
67
101
|
end
|
68
102
|
|
69
103
|
test "duration method basic functionality" do
|
104
|
+
omit_if(@@jruby)
|
70
105
|
assert_nothing_raised{ @icmp.ping }
|
71
106
|
assert_respond_to(@icmp, :duration)
|
72
107
|
assert_kind_of(Float, @icmp.duration)
|
@@ -99,9 +134,15 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
99
134
|
assert_equal(7, @icmp.timeout)
|
100
135
|
end
|
101
136
|
|
137
|
+
test "timeout works as expected" do
|
138
|
+
omit_if(@@jruby)
|
139
|
+
icmp = Net::Ping::ICMP.new('bogus.com', nil, 0.000001)
|
140
|
+
assert_false(icmp.ping?)
|
141
|
+
assert_equal('timeout', icmp.exception)
|
142
|
+
end
|
143
|
+
|
102
144
|
test "exception method basic functionality" do
|
103
145
|
assert_respond_to(@icmp, :exception)
|
104
|
-
assert_nothing_raised{ @icmp.ping }
|
105
146
|
end
|
106
147
|
|
107
148
|
test "exception method returns nil if no ping has happened yet" do
|
@@ -128,6 +169,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
128
169
|
end
|
129
170
|
|
130
171
|
test "setting an odd data_size is valid" do
|
172
|
+
omit_if(@@jruby)
|
131
173
|
assert_nothing_raised{ @icmp.data_size = 57 }
|
132
174
|
assert_boolean(@icmp.ping)
|
133
175
|
end
|
@@ -135,5 +177,10 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
135
177
|
def teardown
|
136
178
|
@host = nil
|
137
179
|
@icmp = nil
|
180
|
+
@concurrency = nil
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.shutdown
|
184
|
+
@@jruby = nil
|
138
185
|
end
|
139
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -102,15 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: 1.9.
|
105
|
+
version: 1.9.3
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubyforge_project:
|
113
|
-
rubygems_version: 2.2.
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: A ping interface for Ruby.
|