net-ping 1.7.3 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +14 -0
- data/lib/net/ping/external.rb +8 -1
- data/lib/net/ping/http.rb +37 -20
- data/lib/net/ping/icmp.rb +31 -29
- data/lib/net/ping/ping.rb +1 -1
- data/net-ping.gemspec +1 -1
- data/test/test_net_ping.rb +1 -1
- data/test/test_net_ping_external.rb +5 -0
- data/test/test_net_ping_http.rb +11 -1
- data/test/test_net_ping_icmp.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 361926b3f3ac0c0f3bceb71cffe723bf10e70503
|
4
|
+
data.tar.gz: 6a0b1f3e9269a1b76ca3d5ba111178295a2ffd91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d445f63c02d900806db92f9e6a88afa463503865332d1a56629d8775b3d7f5916aa3697320da631093861d4256d884bf84c806270be3e4309d7c5e8142774131
|
7
|
+
data.tar.gz: 6aa45f6d23a07235f5ff7f1fef3c72efdc82a5b4943b70da3830e5916e3299fc363f8d53e4ff9674c2247e4696ccd04c470fb6555cf3fa118a693aab6cb26df0
|
data/CHANGES
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== 1.7.4 - 16-Apr-2014
|
2
|
+
* Remove the Timeout block for the Ping::HTTP class because it wasn't working
|
3
|
+
with JRuby. Instead, we use the builtin open_timeout and read_timeout
|
4
|
+
accessors on the underlying http request. Thanks go to Ian Heggie for the
|
5
|
+
spot.
|
6
|
+
* The Ping::HTTP#ping? more robustly parses out the port from the uri argument
|
7
|
+
if provided. In addition, the default port is again set back to 80 as a
|
8
|
+
last resort in the constructor.
|
9
|
+
* Added timeout and port tests for the Ping::HTTP class.
|
10
|
+
* If a host is unreachable explicitly set the result to false regardless of
|
11
|
+
the actual exit status. This appears to only affect Windows 7 and later.
|
12
|
+
* Reinstated the Timeout block for the Ping::ICMP class. Without it, threaded
|
13
|
+
pings could end up in an infinite loop. Thanks go to muirmanders for the spot.
|
14
|
+
|
1
15
|
== 1.7.3 - 3-Apr-2014
|
2
16
|
* Removed the Timeout block for the Ping::External class as it apparently
|
3
17
|
hasn't worked with open3 for some time. Instead, it now uses your command
|
data/lib/net/ping/external.rb
CHANGED
@@ -49,7 +49,14 @@ module Net
|
|
49
49
|
|
50
50
|
case thread.value.exitstatus
|
51
51
|
when 0
|
52
|
-
|
52
|
+
info = stdout.read
|
53
|
+
if info =~ /unreachable/ix # Windows
|
54
|
+
bool = false
|
55
|
+
@exception = "host unreachable"
|
56
|
+
else
|
57
|
+
bool = true # Success, at least one response.
|
58
|
+
end
|
59
|
+
|
53
60
|
if err & err =~ /warning/i
|
54
61
|
@warning = err.chomp
|
55
62
|
end
|
data/lib/net/ping/http.rb
CHANGED
@@ -42,7 +42,7 @@ module Net
|
|
42
42
|
attr_reader :code
|
43
43
|
|
44
44
|
# Creates and returns a new Ping::HTTP object. The default port is the
|
45
|
-
# port associated with the URI. The default timeout is 5 seconds.
|
45
|
+
# port associated with the URI or 80. The default timeout is 5 seconds.
|
46
46
|
#
|
47
47
|
def initialize(uri=nil, port=nil, timeout=5)
|
48
48
|
@follow_redirect = true
|
@@ -52,6 +52,9 @@ module Net
|
|
52
52
|
@code = nil
|
53
53
|
|
54
54
|
port ||= URI.parse(uri).port if uri
|
55
|
+
port ||= 80
|
56
|
+
|
57
|
+
@port = port
|
55
58
|
|
56
59
|
super(uri, port, timeout)
|
57
60
|
end
|
@@ -80,8 +83,10 @@ module Net
|
|
80
83
|
|
81
84
|
uri = URI.parse(host)
|
82
85
|
|
83
|
-
# A port provided here
|
84
|
-
|
86
|
+
# A port provided here via the host argument overrides anything
|
87
|
+
# provided in constructor.
|
88
|
+
#
|
89
|
+
port = URI.split(host)[3] || URI.parse(host).port || @port
|
85
90
|
port = port.to_i
|
86
91
|
|
87
92
|
start_time = Time.now
|
@@ -103,7 +108,7 @@ module Net
|
|
103
108
|
redirect = URI.parse(response['location'])
|
104
109
|
redirect = uri + redirect if redirect.relative?
|
105
110
|
response = do_ping(redirect, port)
|
106
|
-
rlimit
|
111
|
+
rlimit += 1
|
107
112
|
end
|
108
113
|
|
109
114
|
if response.is_a?(Net::HTTPSuccess)
|
@@ -140,31 +145,43 @@ module Net
|
|
140
145
|
|
141
146
|
def do_ping(uri, port)
|
142
147
|
response = nil
|
143
|
-
proxy
|
148
|
+
proxy = uri.find_proxy || URI.parse("")
|
149
|
+
|
144
150
|
begin
|
145
151
|
uri_path = uri.path.empty? ? '/' : uri.path
|
146
|
-
headers = { }
|
147
|
-
headers["User-Agent"] = user_agent unless user_agent.nil?
|
148
|
-
Timeout.timeout(@timeout) do
|
149
|
-
http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(uri.host, port)
|
150
|
-
@proxied = http.proxy?
|
151
|
-
if @get_request == true
|
152
|
-
request = Net::HTTP::Get.new(uri_path)
|
153
|
-
else
|
154
|
-
request = Net::HTTP::Head.new(uri_path)
|
155
|
-
end
|
156
152
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
153
|
+
headers = {}
|
154
|
+
headers["User-Agent"] = user_agent if user_agent
|
155
|
+
|
156
|
+
http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(uri.host, port)
|
157
|
+
|
158
|
+
http.open_timeout = timeout
|
159
|
+
http.read_timeout = timeout
|
161
160
|
|
162
|
-
|
161
|
+
@proxied = http.proxy?
|
162
|
+
|
163
|
+
if @get_request == true
|
164
|
+
request = Net::HTTP::Get.new(uri_path)
|
165
|
+
else
|
166
|
+
request = Net::HTTP::Head.new(uri_path)
|
167
|
+
end
|
168
|
+
|
169
|
+
if uri.scheme == 'https'
|
170
|
+
http.use_ssl = true
|
171
|
+
http.verify_mode = @ssl_verify_mode
|
163
172
|
end
|
173
|
+
|
174
|
+
response = http.start{ |h|
|
175
|
+
h.open_timeout = timeout
|
176
|
+
h.read_timeout = timeout
|
177
|
+
h.request(request)
|
178
|
+
}
|
164
179
|
rescue Exception => err
|
165
180
|
@exception = err.message
|
166
181
|
end
|
182
|
+
|
167
183
|
@code = response.code if response
|
184
|
+
|
168
185
|
response
|
169
186
|
end
|
170
187
|
end
|
data/lib/net/ping/icmp.rb
CHANGED
@@ -107,36 +107,38 @@ module Net
|
|
107
107
|
socket.send(msg, 0, saddr) # Send the message
|
108
108
|
|
109
109
|
begin
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
110
|
+
Timeout.timeout(@timeout){
|
111
|
+
while true
|
112
|
+
io_array = select([socket], nil, nil, timeout)
|
113
|
+
|
114
|
+
if io_array.nil? || io_array[0].empty?
|
115
|
+
@exception = "timeout" if io_array.nil?
|
116
|
+
return false
|
117
|
+
end
|
118
|
+
|
119
|
+
ping_id = nil
|
120
|
+
seq = nil
|
121
|
+
|
122
|
+
data = socket.recvfrom(1500).first
|
123
|
+
type = data[20, 2].unpack('C2').first
|
124
|
+
|
125
|
+
case type
|
126
|
+
when ICMP_ECHOREPLY
|
127
|
+
if data.length >= 28
|
128
|
+
ping_id, seq = data[24, 4].unpack('n3')
|
129
|
+
end
|
130
|
+
else
|
131
|
+
if data.length > 56
|
132
|
+
ping_id, seq = data[52, 4].unpack('n3')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
if ping_id == @ping_id && seq == @seq && type == ICMP_ECHOREPLY
|
137
|
+
bool = true
|
138
|
+
break
|
139
|
+
end
|
133
140
|
end
|
134
|
-
|
135
|
-
if ping_id == @ping_id && seq == @seq && type == ICMP_ECHOREPLY
|
136
|
-
bool = true
|
137
|
-
break
|
138
|
-
end
|
139
|
-
end
|
141
|
+
}
|
140
142
|
rescue Exception => err
|
141
143
|
@exception = err
|
142
144
|
ensure
|
data/lib/net/ping/ping.rb
CHANGED
data/net-ping.gemspec
CHANGED
data/test/test_net_ping.rb
CHANGED
@@ -129,6 +129,11 @@ class TC_Net_Ping_External < Test::Unit::TestCase
|
|
129
129
|
assert_not_nil(ext.exception)
|
130
130
|
end
|
131
131
|
|
132
|
+
test "pinging an unreachable host on the same subnet returns false" do
|
133
|
+
@bad = Net::Ping::External.new('192.168.0.99')
|
134
|
+
assert_false(@bad.ping?)
|
135
|
+
end
|
136
|
+
|
132
137
|
def teardown
|
133
138
|
@host = nil
|
134
139
|
@bogus = nil
|
data/test/test_net_ping_http.rb
CHANGED
@@ -91,8 +91,10 @@ class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
|
91
91
|
assert_respond_to(@http, :port=)
|
92
92
|
end
|
93
93
|
|
94
|
-
test 'port attribute expected value' do
|
94
|
+
test 'port attribute is set to expected value' do
|
95
95
|
assert_equal(80, @http.port)
|
96
|
+
assert_equal(443, Net::Ping::HTTP.new('https://github.com/path').port)
|
97
|
+
assert_equal(80, Net::Ping::HTTP.new.port)
|
96
98
|
end
|
97
99
|
|
98
100
|
test 'timeout attribute basic functionality' do
|
@@ -105,6 +107,14 @@ class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
|
105
107
|
assert_equal(5, @bad.timeout)
|
106
108
|
end
|
107
109
|
|
110
|
+
# TODO: Figure out how to do this with FakeWeb.
|
111
|
+
test 'ping fails if timeout exceeded' do
|
112
|
+
FakeWeb.allow_net_connect = true
|
113
|
+
@http = Net::Ping::HTTP.new('https://github.com/path', 80, 0.01)
|
114
|
+
assert_false(@http.ping?)
|
115
|
+
assert_equal('execution expired', @http.exception)
|
116
|
+
end
|
117
|
+
|
108
118
|
test 'exception attribute basic functionality' do
|
109
119
|
assert_respond_to(@http, :exception)
|
110
120
|
assert_nil(@http.exception)
|
data/test/test_net_ping_icmp.rb
CHANGED
@@ -138,7 +138,7 @@ class TC_PingICMP < Test::Unit::TestCase
|
|
138
138
|
omit_if(@@jruby)
|
139
139
|
icmp = Net::Ping::ICMP.new('bogus.com', nil, 0.000001)
|
140
140
|
assert_false(icmp.ping?)
|
141
|
-
|
141
|
+
assert_kind_of(Timeout::Error, icmp.exception)
|
142
142
|
end
|
143
143
|
|
144
144
|
test "exception method basic functionality" do
|
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.4
|
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-04-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|