net-ping 1.7.3-universal-mingw32 → 1.7.4-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmJiYzkwNzhlZDAzZTAwNjhmZTM5NWQ1YzNiNzVjNDRlMTEzMzFlZQ==
4
+ OTZiY2MzZGJmMmVkYjNmNjYwYzY2NGQ3Njg1YjE4MTk3NDFkMzdmZA==
5
5
  data.tar.gz: !binary |-
6
- Njg1ZGNmNjRjMzYyNDY4MDg0MDE1NjgwZWVjN2E5MTMxZjkwODk2ZA==
6
+ ODM5OWFiNTI3ODgyMTEwMzE2MGM4ODVlOTQ2YzBjMTkyYWI1ZTNkMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzUwZjgzM2VlNjg4NGU4ZDRhM2NiMDk2Y2QxMGFjZDc0YzRiMTdlOTdmYmRk
10
- ZjgzZWRjNGFkNDRjZjc1Yzg5OTg0NDNlYTYwOTU4ZGRjYTRjYzYyN2RjMTE3
11
- MTRhZTc4MTgyODNlZTU2MmVkMjliNTFjMzcyMTJlODY3YjBjZDM=
9
+ YjY1Mzk3NGExZWQ4N2NhNDVhY2NhNjMxMTU3ZjZmODU5NDEyN2E5ZTRmZjMy
10
+ MTliMzc0YjEwNDY3MjU5MGYzZmZhMjlkMjJlYmM0ZjE3ZWZjNWEwNDBhZjJj
11
+ OGRlMzAzMjhhNTM3YTM2ZDYyODI3OWY5NTAxMjAwNzk2MjFjMWM=
12
12
  data.tar.gz: !binary |-
13
- ZmMzNWM4YzU5ODNjMDQxMzhkMTQwNTBhYzJkYjhjZGIzMjBlNWJkY2ZkOWY2
14
- MWE0M2E1NzFmZGE3N2QxZjM5MmRkMjU5NzA3NGZkMTViZGU0MTFkM2UzZmE4
15
- NTVmZjc5MjAwNGIwM2U2OTUxNDU3MDdlZmYyYTMwNmM3YmFlN2Q=
13
+ MmJjN2E0OTBlZDU3ZTdmMTkyMTZmOTIzYzFiMjgwZjRmYzM0MTk1NzFlMzEw
14
+ N2FhYTE1N2U5ZGI3NjA2ZDNlMDFkMDkzNWE3N2RkZWRhOWFlZDQwMDBjMzY4
15
+ YWM0NDIwMzkwNzJlZDc2ZjNmOTQ2ZmNmYzY2YmY1ODhmNWE3OWQ=
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
@@ -49,7 +49,14 @@ module Net
49
49
 
50
50
  case thread.value.exitstatus
51
51
  when 0
52
- bool = true # Success, at least one response.
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 overrides anything provided in constructor
84
- port = URI.split(host)[3] || @port
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 += 1
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 = uri.find_proxy || URI.parse("")
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
- if uri.scheme == 'https'
158
- http.use_ssl = true
159
- http.verify_mode = @ssl_verify_mode
160
- end
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
- response = http.start { |h| h.request(request) }
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
- 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
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
@@ -10,7 +10,7 @@ module Net
10
10
  #
11
11
  class Ping
12
12
  # The version of the net-ping library.
13
- VERSION = '1.7.3'
13
+ VERSION = '1.7.4'
14
14
 
15
15
  # The host to ping. In the case of Ping::HTTP, this is the URI.
16
16
  attr_accessor :host
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.3'
6
+ spec.version = '1.7.4'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.author = 'Daniel J. Berger'
9
9
  spec.email = 'djberg96@gmail.com'
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  class TC_Net_Ping < Test::Unit::TestCase
30
30
  def test_net_ping_version
31
- assert_equal('1.7.3', Net::Ping::VERSION)
31
+ assert_equal('1.7.4', Net::Ping::VERSION)
32
32
  end
33
33
  end
34
34
 
@@ -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
@@ -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)
@@ -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
- assert_equal('timeout', icmp.exception)
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.3
4
+ version: 1.7.4
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit