net-ping 1.5.3 → 1.6.0
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 +4 -0
- data/Gemfile +2 -0
- data/Rakefile +0 -11
- data/lib/net/ping.rb +1 -2
- data/lib/net/ping/http.rb +20 -15
- data/lib/net/ping/ping.rb +1 -1
- data/net-ping.gemspec +4 -6
- data/test/test_net_ping.rb +2 -4
- data/test/test_net_ping_external.rb +1 -4
- data/test/test_net_ping_http.rb +32 -4
- data/test/test_net_ping_icmp.rb +1 -4
- data/test/test_net_ping_tcp.rb +1 -4
- data/test/test_net_ping_udp.rb +1 -4
- data/test/test_net_ping_wmi.rb +1 -4
- metadata +80 -129
- data/examples/example_pingldap.rb +0 -22
- data/lib/net/ping/ldap.rb +0 -107
- data/test/test_net_ping_ldap.rb +0 -200
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 1.6.0 - 19-Mar-2013
|
2
|
+
* Split out the ldap portion of the code into its own branch.
|
3
|
+
* Don't require resolv-replace on Ruby 1.9.3 or later.
|
4
|
+
|
1
5
|
== 1.5.3 - 29-Feb-2012
|
2
6
|
* Removed the Windows::Console dependency and replaced it with FFI since there
|
3
7
|
were only two functions needed. This had the nice side effect of making it
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -39,11 +39,6 @@ namespace 'example' do
|
|
39
39
|
task :udp do
|
40
40
|
ruby '-Ilib examples/example_pingudp.rb'
|
41
41
|
end
|
42
|
-
|
43
|
-
desc 'Run the ldap ping example program'
|
44
|
-
task :ldap do
|
45
|
-
ruby '-Ilib examples/example_pingldap.rb'
|
46
|
-
end
|
47
42
|
end
|
48
43
|
|
49
44
|
Rake::TestTask.new do |t|
|
@@ -89,12 +84,6 @@ namespace 'test' do
|
|
89
84
|
t.verbose = true
|
90
85
|
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
91
86
|
end
|
92
|
-
|
93
|
-
Rake::TestTask.new('ldap') do |t|
|
94
|
-
t.warning = true
|
95
|
-
t.verbose = true
|
96
|
-
t.test_files = FileList['test/test_net_ping_ldap.rb']
|
97
|
-
end
|
98
87
|
end
|
99
88
|
|
100
89
|
task :default => :test
|
data/lib/net/ping.rb
CHANGED
@@ -9,10 +9,9 @@ require File.join(File.dirname(__FILE__), 'ping/udp')
|
|
9
9
|
require File.join(File.dirname(__FILE__), 'ping/icmp')
|
10
10
|
require File.join(File.dirname(__FILE__), 'ping/external')
|
11
11
|
require File.join(File.dirname(__FILE__), 'ping/http')
|
12
|
-
require File.join(File.dirname(__FILE__), 'ping/ldap')
|
13
12
|
|
14
13
|
RbConfig = Config unless Object.const_defined?(:RbConfig)
|
15
14
|
|
16
|
-
if
|
15
|
+
if File::ALT_SEPARATOR
|
17
16
|
require File.join(File.dirname(__FILE__), 'ping/wmi')
|
18
17
|
end
|
data/lib/net/ping/http.rb
CHANGED
@@ -2,10 +2,11 @@ require File.join(File.dirname(__FILE__), 'ping')
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'net/https'
|
4
4
|
require 'uri'
|
5
|
+
require 'open-uri'
|
5
6
|
|
6
7
|
# Force non-blocking Socket.getaddrinfo on Unix systems. Do not use on
|
7
8
|
# Windows because it (ironically) causes blocking problems.
|
8
|
-
unless File::ALT_SEPARATOR
|
9
|
+
unless File::ALT_SEPARATOR or RUBY_VERSION >= "1.9.3"
|
9
10
|
require 'resolv-replace'
|
10
11
|
end
|
11
12
|
|
@@ -33,6 +34,9 @@ module Net
|
|
33
34
|
# Use GET request instead HEAD. The default is false.
|
34
35
|
attr_accessor :get_request
|
35
36
|
|
37
|
+
# was this ping proxied?
|
38
|
+
attr_accessor :proxied
|
39
|
+
|
36
40
|
# Creates and returns a new Ping::HTTP object. The default port is the
|
37
41
|
# port associated with the URI. The default timeout is 5 seconds.
|
38
42
|
#
|
@@ -40,7 +44,7 @@ module Net
|
|
40
44
|
@follow_redirect = true
|
41
45
|
@redirect_limit = 5
|
42
46
|
@ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
-
@get_request
|
47
|
+
@get_request = false
|
44
48
|
|
45
49
|
port ||= URI.parse(uri).port if uri
|
46
50
|
|
@@ -64,7 +68,7 @@ module Net
|
|
64
68
|
def ping(host = @host)
|
65
69
|
super(host)
|
66
70
|
bool = false
|
67
|
-
uri
|
71
|
+
uri = URI.parse(host)
|
68
72
|
|
69
73
|
start_time = Time.now
|
70
74
|
|
@@ -75,7 +79,7 @@ module Net
|
|
75
79
|
elsif redirect?(response) # Check code, HTTPRedirection does not always work
|
76
80
|
if @follow_redirect
|
77
81
|
@warning = response.message
|
78
|
-
rlimit
|
82
|
+
rlimit = 0
|
79
83
|
|
80
84
|
while redirect?(response)
|
81
85
|
if rlimit >= redirect_limit
|
@@ -85,13 +89,13 @@ module Net
|
|
85
89
|
redirect = URI.parse(response['location'])
|
86
90
|
redirect = uri + redirect if redirect.relative?
|
87
91
|
response = do_ping(redirect)
|
88
|
-
rlimit
|
92
|
+
rlimit += 1
|
89
93
|
end
|
90
94
|
|
91
95
|
if response.is_a?(Net::HTTPSuccess)
|
92
96
|
bool = true
|
93
97
|
else
|
94
|
-
@warning
|
98
|
+
@warning = nil
|
95
99
|
@exception ||= response.message
|
96
100
|
end
|
97
101
|
|
@@ -120,25 +124,26 @@ module Net
|
|
120
124
|
|
121
125
|
def do_ping(uri)
|
122
126
|
response = nil
|
127
|
+
proxy = uri.find_proxy || URI.parse("")
|
123
128
|
begin
|
124
129
|
uri_path = uri.path.empty? ? '/' : uri.path
|
125
|
-
headers
|
130
|
+
headers = { }
|
126
131
|
headers["User-Agent"] = user_agent unless user_agent.nil?
|
127
132
|
Timeout.timeout(@timeout) do
|
128
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
129
|
-
|
130
|
-
if uri.scheme == 'https'
|
131
|
-
http.use_ssl = true
|
132
|
-
http.verify_mode = @ssl_verify_mode
|
133
|
-
end
|
134
|
-
|
133
|
+
http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(uri.host, uri.port)
|
134
|
+
@proxied = http.proxy?
|
135
135
|
if @get_request == true
|
136
136
|
request = Net::HTTP::Get.new(uri_path)
|
137
137
|
else
|
138
138
|
request = Net::HTTP::Head.new(uri_path)
|
139
139
|
end
|
140
140
|
|
141
|
-
|
141
|
+
if uri.scheme == 'https'
|
142
|
+
http.use_ssl = true
|
143
|
+
http.verify_mode = @ssl_verify_mode
|
144
|
+
end
|
145
|
+
|
146
|
+
response = http.start { |h| h.request(request) }
|
142
147
|
end
|
143
148
|
rescue Exception => err
|
144
149
|
@exception = err.message
|
data/lib/net/ping/ping.rb
CHANGED
data/net-ping.gemspec
CHANGED
@@ -3,11 +3,11 @@ require 'rbconfig'
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'net-ping'
|
6
|
-
spec.version = '1.
|
6
|
+
spec.version = '1.6.0'
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.author = 'Daniel J. Berger'
|
9
9
|
spec.email = 'djberg96@gmail.com'
|
10
|
-
spec.homepage = '
|
10
|
+
spec.homepage = 'https://github.com/djberg96/net-ping'
|
11
11
|
spec.summary = 'A ping interface for Ruby.'
|
12
12
|
spec.test_file = 'test/test_net_ping.rb'
|
13
13
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
@@ -15,12 +15,10 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.rubyforge_project = 'shards'
|
16
16
|
spec.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
|
17
17
|
|
18
|
-
spec.add_dependency('net-ldap', '~> 0.2.2')
|
19
18
|
spec.add_dependency('ffi', '>= 1.0.0')
|
20
19
|
|
21
|
-
spec.add_development_dependency('test-unit', '>= 2.
|
20
|
+
spec.add_development_dependency('test-unit', '>= 2.5.0')
|
22
21
|
spec.add_development_dependency('fakeweb', '>= 1.3.0')
|
23
|
-
spec.add_development_dependency('fakeldap', '~> 0.0.1')
|
24
22
|
|
25
23
|
if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
|
26
24
|
spec.platform = Gem::Platform::CURRENT
|
@@ -28,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
28
26
|
spec.platform.version = nil
|
29
27
|
|
30
28
|
# Used primarily for icmp pings.
|
31
|
-
spec.add_development_dependency('win32-security', '>=
|
29
|
+
spec.add_development_dependency('win32-security', '>= 0.2.0')
|
32
30
|
|
33
31
|
if RUBY_VERSION.to_f < 1.9
|
34
32
|
spec.add_dependency('win32-open3', '>= 0.3.1')
|
data/test/test_net_ping.rb
CHANGED
@@ -12,10 +12,8 @@ require 'fakeweb'
|
|
12
12
|
|
13
13
|
if File::ALT_SEPARATOR
|
14
14
|
require 'win32/security'
|
15
|
-
require 'windows/system_info'
|
16
|
-
include Windows::SystemInfo
|
17
15
|
|
18
|
-
if
|
16
|
+
if Win32::Security.elevated_security?
|
19
17
|
require 'test_net_ping_icmp'
|
20
18
|
end
|
21
19
|
else
|
@@ -30,7 +28,7 @@ end
|
|
30
28
|
|
31
29
|
class TC_Net_Ping < Test::Unit::TestCase
|
32
30
|
def test_net_ping_version
|
33
|
-
assert_equal('1.
|
31
|
+
assert_equal('1.6.0', Net::Ping::VERSION)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -4,10 +4,7 @@
|
|
4
4
|
# Test case for the Net::PingExternal class. Run this via the 'test' or
|
5
5
|
# 'test:external' rake task.
|
6
6
|
#########################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'net/ping/external'
|
12
9
|
|
13
10
|
class TC_Net_Ping_External < Test::Unit::TestCase
|
data/test/test_net_ping_http.rb
CHANGED
@@ -4,25 +4,29 @@
|
|
4
4
|
# Test case for the Net::PingHTTP class. This should be run via the 'test' or
|
5
5
|
# 'test:http' Rake task.
|
6
6
|
#################################################################################
|
7
|
-
require '
|
8
|
-
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
8
|
+
require 'fakeweb'
|
11
9
|
require 'net/ping/http'
|
12
10
|
|
13
11
|
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
14
12
|
def setup
|
13
|
+
ENV['http_proxy'] = ENV['https_proxy'] = ENV['no_proxy'] = nil
|
15
14
|
@uri = 'http://www.google.com/index.html'
|
16
15
|
@uri_https = 'https://encrypted.google.com'
|
16
|
+
@proxy = 'http://username:password@proxymoxie:3128'
|
17
|
+
FakeWeb.allow_net_connect = false
|
17
18
|
|
18
19
|
FakeWeb.register_uri(:get, @uri, :body => "PONG")
|
19
20
|
FakeWeb.register_uri(:head, @uri, :body => "PONG")
|
20
21
|
FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
|
22
|
+
FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
|
21
23
|
FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
|
22
24
|
:body => "PONG",
|
23
25
|
:location => "#{@uri}",
|
24
26
|
:status => ["302", "Found"])
|
25
27
|
|
28
|
+
FakeWeb.register_uri(:any, 'http://www.blabfoobarurghxxxx.com', :exception => SocketError)
|
29
|
+
|
26
30
|
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
27
31
|
@bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
|
28
32
|
end
|
@@ -175,6 +179,30 @@ class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
|
175
179
|
assert_true(@http.ping)
|
176
180
|
end
|
177
181
|
|
182
|
+
test 'ping with http proxy' do
|
183
|
+
ENV['http_proxy'] = "http://proxymoxie:3128"
|
184
|
+
@http = Net::Ping::HTTP.new(@uri)
|
185
|
+
@http.get_request = true
|
186
|
+
assert_true(@http.ping)
|
187
|
+
assert_true(@http.proxied)
|
188
|
+
end
|
189
|
+
|
190
|
+
test 'ping with https proxy' do
|
191
|
+
ENV['https_proxy'] = "http://proxymoxie:3128"
|
192
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
193
|
+
@http.get_request = true
|
194
|
+
assert_true(@http.ping)
|
195
|
+
assert_true(@http.proxied)
|
196
|
+
end
|
197
|
+
|
198
|
+
test 'ping with no_proxy' do
|
199
|
+
ENV['no_proxy'] = "google.com"
|
200
|
+
@http = Net::Ping::HTTP.new(@uri)
|
201
|
+
@http.get_request = true
|
202
|
+
assert_true(@http.ping)
|
203
|
+
assert_false(@http.proxied)
|
204
|
+
end
|
205
|
+
|
178
206
|
def teardown
|
179
207
|
@uri = nil
|
180
208
|
@http = nil
|
data/test/test_net_ping_icmp.rb
CHANGED
@@ -5,10 +5,7 @@
|
|
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
|
-
require '
|
9
|
-
gem 'test-unit'
|
10
|
-
|
11
|
-
require 'test/unit'
|
8
|
+
require 'test-unit'
|
12
9
|
require 'net/ping/icmp'
|
13
10
|
include Net
|
14
11
|
|
data/test/test_net_ping_tcp.rb
CHANGED
@@ -4,10 +4,7 @@
|
|
4
4
|
# Test case for the Net::PingTCP class. This test should be run via
|
5
5
|
# the 'test' or 'test:tcp' Rake task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'net/ping/tcp'
|
12
9
|
include Net
|
13
10
|
|
data/test/test_net_ping_udp.rb
CHANGED
@@ -7,10 +7,7 @@
|
|
7
7
|
# If someone could provide me a host where a udp ping actually
|
8
8
|
# works (with a service check), I would appreciate it. :)
|
9
9
|
########################################################################
|
10
|
-
require '
|
11
|
-
gem 'test-unit'
|
12
|
-
|
13
|
-
require 'test/unit'
|
10
|
+
require 'test-unit'
|
14
11
|
require 'net/ping/udp'
|
15
12
|
|
16
13
|
class TC_Net_Ping_UDP < Test::Unit::TestCase
|
data/test/test_net_ping_wmi.rb
CHANGED
@@ -5,10 +5,7 @@
|
|
5
5
|
# run MS Windows. You should run this test via the 'test' or
|
6
6
|
# 'test:wmi' Rake task.
|
7
7
|
#######################################################################
|
8
|
-
require '
|
9
|
-
gem 'test-unit'
|
10
|
-
|
11
|
-
require 'test/unit'
|
8
|
+
require 'test-unit'
|
12
9
|
require 'net/ping/wmi'
|
13
10
|
include Net
|
14
11
|
|
metadata
CHANGED
@@ -1,173 +1,124 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ping
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 3
|
10
|
-
version: 1.5.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Daniel J. Berger
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 2
|
32
|
-
- 2
|
33
|
-
version: 0.2.2
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
34
22
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: ffi
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
25
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 23
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
- 0
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
49
29
|
version: 1.0.0
|
50
|
-
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
30
|
+
- !ruby/object:Gem::Dependency
|
53
31
|
name: test-unit
|
54
|
-
|
55
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
56
33
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 2
|
63
|
-
- 1
|
64
|
-
- 2
|
65
|
-
version: 2.1.2
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.0
|
66
38
|
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: fakeweb
|
70
39
|
prerelease: false
|
71
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
41
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakeweb
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
81
53
|
version: 1.3.0
|
82
54
|
type: :development
|
83
|
-
version_requirements: *id004
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: fakeldap
|
86
55
|
prerelease: false
|
87
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
57
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
- 0
|
96
|
-
- 1
|
97
|
-
version: 0.0.1
|
98
|
-
type: :development
|
99
|
-
version_requirements: *id005
|
100
|
-
description: " The net-ping library provides a ping interface for Ruby. It includes\n separate TCP, HTTP, LDAP, ICMP, UDP, WMI (for Windows) and external ping\n classes.\n"
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
description: ! " The net-ping library provides a ping interface for Ruby. It includes\n
|
63
|
+
\ separate TCP, HTTP, LDAP, ICMP, UDP, WMI (for Windows) and external ping\n classes.\n"
|
101
64
|
email: djberg96@gmail.com
|
102
65
|
executables: []
|
103
|
-
|
104
66
|
extensions: []
|
105
|
-
|
106
|
-
extra_rdoc_files:
|
67
|
+
extra_rdoc_files:
|
107
68
|
- README
|
108
69
|
- CHANGES
|
109
70
|
- doc/ping.txt
|
110
|
-
files:
|
111
|
-
- CHANGES
|
71
|
+
files:
|
112
72
|
- doc/ping.txt
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
73
|
+
- test/test_net_ping_tcp.rb
|
74
|
+
- test/test_net_ping_http.rb
|
75
|
+
- test/test_net_ping_udp.rb
|
76
|
+
- test/test_net_ping_external.rb
|
77
|
+
- test/test_net_ping_icmp.rb
|
78
|
+
- test/test_net_ping.rb
|
79
|
+
- test/test_net_ping_wmi.rb
|
80
|
+
- Gemfile
|
81
|
+
- Rakefile
|
82
|
+
- net-ping.gemspec
|
83
|
+
- MANIFEST
|
84
|
+
- CHANGES
|
85
|
+
- lib/net/ping.rb
|
86
|
+
- lib/net/ping/tcp.rb
|
120
87
|
- lib/net/ping/icmp.rb
|
121
|
-
- lib/net/ping/ldap.rb
|
122
88
|
- lib/net/ping/ping.rb
|
123
|
-
- lib/net/ping/tcp.rb
|
124
|
-
- lib/net/ping/udp.rb
|
125
89
|
- lib/net/ping/wmi.rb
|
126
|
-
- lib/net/ping.rb
|
127
|
-
-
|
128
|
-
- net
|
129
|
-
- Rakefile
|
90
|
+
- lib/net/ping/external.rb
|
91
|
+
- lib/net/ping/http.rb
|
92
|
+
- lib/net/ping/udp.rb
|
130
93
|
- README
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
|
136
|
-
|
137
|
-
- test/test_net_ping_udp.rb
|
138
|
-
- test/test_net_ping_wmi.rb
|
139
|
-
homepage: http://www.rubyforge.org/projects/shards
|
140
|
-
licenses:
|
94
|
+
- examples/example_pingtcp.rb
|
95
|
+
- examples/example_pingexternal.rb
|
96
|
+
- examples/example_pingudp.rb
|
97
|
+
- examples/example_pinghttp.rb
|
98
|
+
homepage: https://github.com/djberg96/net-ping
|
99
|
+
licenses:
|
141
100
|
- Artistic 2.0
|
142
101
|
post_install_message:
|
143
102
|
rdoc_options: []
|
144
|
-
|
145
|
-
require_paths:
|
103
|
+
require_paths:
|
146
104
|
- lib
|
147
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
106
|
none: false
|
149
|
-
requirements:
|
150
|
-
- -
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
|
153
|
-
|
154
|
-
- 0
|
155
|
-
version: "0"
|
156
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
112
|
none: false
|
158
|
-
requirements:
|
159
|
-
- -
|
160
|
-
- !ruby/object:Gem::Version
|
161
|
-
|
162
|
-
segments:
|
163
|
-
- 0
|
164
|
-
version: "0"
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
165
117
|
requirements: []
|
166
|
-
|
167
118
|
rubyforge_project: shards
|
168
|
-
rubygems_version: 1.8.
|
119
|
+
rubygems_version: 1.8.23
|
169
120
|
signing_key:
|
170
121
|
specification_version: 3
|
171
122
|
summary: A ping interface for Ruby.
|
172
|
-
test_files:
|
123
|
+
test_files:
|
173
124
|
- test/test_net_ping.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
########################################################################
|
2
|
-
# example_pingldap.rb
|
3
|
-
#
|
4
|
-
# A short sample program demonstrating an ldap ping. You can run
|
5
|
-
# this program via the example:ldap task. Modify as you see fit.
|
6
|
-
########################################################################
|
7
|
-
require 'net/ping/ldap'
|
8
|
-
|
9
|
-
good = 'ldap://localhost'
|
10
|
-
bad = 'ldap://example.com'
|
11
|
-
|
12
|
-
puts "== Good ping (if you have an ldap server at #{good})"
|
13
|
-
|
14
|
-
p1 = Net::Ping::LDAP.new(good)
|
15
|
-
p p1.ping?
|
16
|
-
|
17
|
-
puts "== Bad ping"
|
18
|
-
|
19
|
-
p2 = Net::Ping::LDAP.new(bad)
|
20
|
-
p p2.ping?
|
21
|
-
p p2.warning
|
22
|
-
p p2.exception
|
data/lib/net/ping/ldap.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'ping')
|
2
|
-
require 'net/ldap'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
|
6
|
-
# The Net module serves as a namespace only.
|
7
|
-
module Net
|
8
|
-
|
9
|
-
# The Ping::LDAP class encapsulates methods for LDAP pings.
|
10
|
-
class Ping::LDAP < Ping
|
11
|
-
|
12
|
-
# uri contains the URI object for the request
|
13
|
-
#
|
14
|
-
attr_accessor :uri
|
15
|
-
|
16
|
-
# username and password may be set for ping using
|
17
|
-
# an authenticated LDAP bind
|
18
|
-
#
|
19
|
-
attr_accessor :username
|
20
|
-
attr_accessor :password
|
21
|
-
|
22
|
-
# set/get the encryption method. By default nil,
|
23
|
-
# but may be set to :simple_tls
|
24
|
-
#
|
25
|
-
attr_accessor :encryption
|
26
|
-
def encryption=(value)
|
27
|
-
@encryption = (value.is_a? Symbol) ? value : value.to_sym
|
28
|
-
end
|
29
|
-
|
30
|
-
# Creates and returns a new Ping::LDAP object.
|
31
|
-
# The default +timeout+ is 5 seconds.
|
32
|
-
#
|
33
|
-
# +uri+ string is expected to be a full URI with scheme (ldap/ldaps)
|
34
|
-
# and optionally the port (else default port is assumed) e.g.
|
35
|
-
# ldap://my.ldap.host.com
|
36
|
-
# ldap://my.ldap.host.com:1389
|
37
|
-
# ldaps://my.ldap.host.com
|
38
|
-
# ldaps://my.ldap.host.com:6636
|
39
|
-
#
|
40
|
-
# If a plain hostname is provided as the +uri+, a default port of 389 is assumed
|
41
|
-
#
|
42
|
-
def initialize(uri=nil, timeout=5)
|
43
|
-
host, port = decode_uri(uri)
|
44
|
-
super(host, port, timeout)
|
45
|
-
end
|
46
|
-
|
47
|
-
# method used to decode uri string
|
48
|
-
#
|
49
|
-
def decode_uri(value)
|
50
|
-
@uri = URI.parse(value)
|
51
|
-
if uri.scheme =~ /ldap/
|
52
|
-
p = @port = uri.port
|
53
|
-
h = @host = uri.host
|
54
|
-
@encryption = uri.scheme=='ldaps' ? :simple_tls : nil
|
55
|
-
else
|
56
|
-
h = value
|
57
|
-
p = 389
|
58
|
-
end
|
59
|
-
[h, p]
|
60
|
-
end
|
61
|
-
|
62
|
-
# constructs the LDAP configuration structure
|
63
|
-
#
|
64
|
-
def config
|
65
|
-
{
|
66
|
-
:host => uri.host,
|
67
|
-
:port => uri.port,
|
68
|
-
:encryption => encryption
|
69
|
-
}.merge(
|
70
|
-
(username && password) ?
|
71
|
-
{ :auth => {:method => :simple, :username => username, :password => password} } :
|
72
|
-
{ :auth => {:method => :anonymous} }
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
# perform ping, optionally providing the ping destination uri
|
77
|
-
#
|
78
|
-
def ping(host = nil)
|
79
|
-
decode_uri(host) if host
|
80
|
-
super(@host)
|
81
|
-
|
82
|
-
bool = false
|
83
|
-
|
84
|
-
start_time = Time.now
|
85
|
-
|
86
|
-
begin
|
87
|
-
Timeout.timeout(@timeout) do
|
88
|
-
Net::LDAP.new( config ).bind
|
89
|
-
end
|
90
|
-
rescue Net::LDAP::LdapError => e
|
91
|
-
@exception = e.message
|
92
|
-
rescue Exception => e
|
93
|
-
@exception = e.message
|
94
|
-
else
|
95
|
-
bool = true
|
96
|
-
end
|
97
|
-
|
98
|
-
# There is no duration if the ping failed
|
99
|
-
@duration = Time.now - start_time if bool
|
100
|
-
|
101
|
-
bool
|
102
|
-
end
|
103
|
-
|
104
|
-
alias ping? ping
|
105
|
-
alias pingecho ping
|
106
|
-
end
|
107
|
-
end
|
data/test/test_net_ping_ldap.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
#################################################################################
|
2
|
-
# test_net_ping_http.rb
|
3
|
-
#
|
4
|
-
# Test case for the Net::PingHTTP class. This should be run via the 'test' or
|
5
|
-
# 'test:http' Rake task.
|
6
|
-
#################################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'net/ping/ldap'
|
12
|
-
require 'fakeldap'
|
13
|
-
|
14
|
-
class TC_Net_Ping_LDAP < Test::Unit::TestCase
|
15
|
-
class << self
|
16
|
-
def startup
|
17
|
-
@@host = 'localhost'
|
18
|
-
@@port = 2389
|
19
|
-
@@uri = "ldap://#{@@host}:#{@@port}"
|
20
|
-
@@timeout = 30
|
21
|
-
@@cn = 'el.Daper'
|
22
|
-
@@password = 'ldappassword'
|
23
|
-
|
24
|
-
@@ldap_server = FakeLDAP::Server.new(:port => @@port)
|
25
|
-
@@ldap_server.run_tcpserver
|
26
|
-
@@ldap_server.add_user("cn=#{@@cn},ou=USERS,dc=example,dc=com", @@password)
|
27
|
-
end
|
28
|
-
def shutdown
|
29
|
-
@@ldap_server.stop
|
30
|
-
end
|
31
|
-
end
|
32
|
-
def setup
|
33
|
-
@ldap = Net::Ping::LDAP.new(@@uri, @@timeout)
|
34
|
-
@ldap.username = @@cn
|
35
|
-
@ldap.password = @@password
|
36
|
-
@bogus = 'ldap://blabfoobarurghxxxx.com' # One hopes so
|
37
|
-
@bad = Net::Ping::LDAP.new(@bogus)
|
38
|
-
end
|
39
|
-
|
40
|
-
def teardown
|
41
|
-
@ldap = nil
|
42
|
-
end
|
43
|
-
|
44
|
-
test 'ping basic functionality' do
|
45
|
-
assert_respond_to(@ldap, :ping)
|
46
|
-
assert_nothing_raised{ @ldap.ping }
|
47
|
-
end
|
48
|
-
|
49
|
-
test 'ping returns a boolean value' do
|
50
|
-
assert_boolean(@ldap.ping?)
|
51
|
-
assert_boolean(@bad.ping?)
|
52
|
-
end
|
53
|
-
|
54
|
-
test 'ping? is an alias for ping' do
|
55
|
-
assert_alias_method(@ldap, :ping?, :ping)
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'pingecho is an alias for ping' do
|
59
|
-
assert_alias_method(@ldap, :pingecho, :ping)
|
60
|
-
end
|
61
|
-
|
62
|
-
test 'ping should succeed for a valid website' do
|
63
|
-
assert_true(@ldap.ping?)
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'ping should fail for an invalid website' do
|
67
|
-
assert_false(@bad.ping?)
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'duration basic functionality' do
|
71
|
-
assert_respond_to(@ldap, :duration)
|
72
|
-
assert_nothing_raised{ @ldap.ping }
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'duration returns a float value on a successful ping' do
|
76
|
-
assert_true(@ldap.ping)
|
77
|
-
assert_kind_of(Float, @ldap.duration)
|
78
|
-
end
|
79
|
-
|
80
|
-
test 'duration is nil on an unsuccessful ping' do
|
81
|
-
assert_false(@bad.ping)
|
82
|
-
assert_nil(@ldap.duration)
|
83
|
-
end
|
84
|
-
|
85
|
-
test "duration is unset if a bad ping follows a good ping" do
|
86
|
-
assert_true{ @ldap.ping }
|
87
|
-
assert_not_nil(@ldap.duration)
|
88
|
-
assert_false(@ldap.ping?(@bogus))
|
89
|
-
assert_nil(@ldap.duration)
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'host attribute basic functionality' do
|
93
|
-
assert_respond_to(@ldap, :host)
|
94
|
-
assert_respond_to(@ldap, :host=)
|
95
|
-
assert_equal(@@host, @ldap.host)
|
96
|
-
end
|
97
|
-
|
98
|
-
test 'port attribute basic functionality' do
|
99
|
-
assert_respond_to(@ldap, :port)
|
100
|
-
assert_respond_to(@ldap, :port=)
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'port attribute expected value' do
|
104
|
-
assert_equal(@@port, @ldap.port)
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'timeout attribute basic functionality' do
|
108
|
-
assert_respond_to(@ldap, :timeout)
|
109
|
-
assert_respond_to(@ldap, :timeout=)
|
110
|
-
end
|
111
|
-
|
112
|
-
test 'timeout attribute expected values' do
|
113
|
-
assert_equal(@@timeout, @ldap.timeout)
|
114
|
-
assert_equal(5, @bad.timeout)
|
115
|
-
end
|
116
|
-
|
117
|
-
test 'exception attribute basic functionality' do
|
118
|
-
assert_respond_to(@ldap, :exception)
|
119
|
-
assert_nil(@ldap.exception)
|
120
|
-
end
|
121
|
-
|
122
|
-
test 'exception attribute is nil if the ping is successful' do
|
123
|
-
assert_true(@ldap.ping)
|
124
|
-
assert_nil(@ldap.exception)
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'exception attribute is not nil if the ping is unsuccessful' do
|
128
|
-
assert_false(@bad.ping)
|
129
|
-
assert_not_nil(@bad.exception)
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'warning attribute basic functionality' do
|
133
|
-
assert_respond_to(@ldap, :warning)
|
134
|
-
assert_nil(@ldap.warning)
|
135
|
-
end
|
136
|
-
|
137
|
-
test 'uri attribute basic functionality' do
|
138
|
-
assert_respond_to(@ldap, :uri)
|
139
|
-
assert_respond_to(@ldap, :uri=)
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'username attribute basic functionality' do
|
143
|
-
assert_respond_to(@ldap, :username)
|
144
|
-
assert_respond_to(@ldap, :username=)
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'password attribute basic functionality' do
|
148
|
-
assert_respond_to(@ldap, :password)
|
149
|
-
assert_respond_to(@ldap, :password=)
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'encryption attribute basic functionality' do
|
153
|
-
assert_respond_to(@ldap, :encryption)
|
154
|
-
assert_respond_to(@ldap, :encryption=)
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'encryption defaults to nil for ldap' do
|
158
|
-
assert_nil(Net::Ping::LDAP.new('ldap://somehost.example.net').encryption)
|
159
|
-
end
|
160
|
-
|
161
|
-
test 'encryption defaults to simple_tls for ldaps' do
|
162
|
-
assert_equal(:simple_tls, Net::Ping::LDAP.new('ldaps://somehost.example.net').encryption)
|
163
|
-
end
|
164
|
-
|
165
|
-
test 'port defaults to 389 for ldap' do
|
166
|
-
assert_equal(389, Net::Ping::LDAP.new('ldap://somehost.example.net').port)
|
167
|
-
end
|
168
|
-
|
169
|
-
test 'port defaults to 636 for ldaps' do
|
170
|
-
assert_equal(636, Net::Ping::LDAP.new('ldaps://somehost.example.net').port)
|
171
|
-
end
|
172
|
-
|
173
|
-
test 'port extracted from uri if provided' do
|
174
|
-
assert_equal(12345, Net::Ping::LDAP.new('ldap://somehost.example.net:12345').port)
|
175
|
-
assert_equal(12345, Net::Ping::LDAP.new('ldaps://somehost.example.net:12345').port)
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'encryption setting is forced to symbol' do
|
179
|
-
@ldap.encryption = 'simple_tls'
|
180
|
-
assert_true( @ldap.encryption.is_a? Symbol )
|
181
|
-
assert_true( @ldap.config[:encryption].is_a? Symbol )
|
182
|
-
end
|
183
|
-
|
184
|
-
test 'username/password set in config auth section' do
|
185
|
-
@ldap.username, @ldap.password = 'fred', 'derf'
|
186
|
-
assert_equal('fred', @ldap.config[:auth][:username] )
|
187
|
-
assert_equal('derf', @ldap.config[:auth][:password] )
|
188
|
-
end
|
189
|
-
|
190
|
-
test 'auth method defaults to simple if username/password set' do
|
191
|
-
@ldap.username, @ldap.password = 'fred', 'derf'
|
192
|
-
assert_equal(:simple, @ldap.config[:auth][:method] )
|
193
|
-
end
|
194
|
-
|
195
|
-
test 'if no username/password then defaults to auth anonymous' do
|
196
|
-
@ldap.username = @ldap.password = nil
|
197
|
-
assert_equal({:method => :anonymous}, @ldap.config[:auth] )
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|