net-ping 1.4.1-x86-mingw32 → 1.5.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/net/ping/wmi.rb CHANGED
@@ -1,118 +1,118 @@
1
- require File.join(File.dirname(__FILE__), 'ping')
2
- require 'win32ole'
3
-
4
- # The Net module serves as a namespace only.
5
- #
6
- module Net
7
-
8
- # The Ping::WMI class encapsulates the Win32_PingStatus WMI class for
9
- # MS Windows.
10
- #
11
- class Ping::WMI < Ping
12
-
13
- PingStatus = Struct.new(
14
- 'PingStatus',
15
- :address,
16
- :buffer_size,
17
- :no_fragmentation,
18
- :primary_address_resolution_status,
19
- :protocol_address,
20
- :protocol_address_resolved,
21
- :record_route,
22
- :reply_inconsistency,
23
- :reply_size,
24
- :resolve_address_names,
25
- :response_time,
26
- :response_time_to_live,
27
- :route_record,
28
- :route_record_resolved,
29
- :source_route,
30
- :source_route_type,
31
- :status_code,
32
- :timeout,
33
- :timestamp_record,
34
- :timestamp_record_address,
35
- :timestamp_record_address_resolved,
36
- :timestamp_route,
37
- :time_to_live,
38
- :type_of_service
39
- )
40
-
41
- # Unlike the ping method for other Ping subclasses, this version returns
42
- # a PingStatus struct which contains various bits of information about
43
- # the results of the ping itself, such as response time.
44
- #
45
- # In addition, this version allows you to pass certain options that are
46
- # then passed on to the underlying WQL query. See the MSDN documentation
47
- # on Win32_PingStatus for details.
48
- #
49
- # Examples:
50
- #
51
- # # Ping with no options
52
- # Ping::WMI.ping('www.perl.com')
53
- #
54
- # # Ping with options
55
- # Ping::WMI.ping('www.perl.com', :BufferSize => 64, :NoFragmentation => true)
56
- #--
57
- # The PingStatus struct is a wrapper for the Win32_PingStatus WMI class.
58
- #
59
- def ping(host = @host, options = {})
60
- super(host)
61
-
62
- lhost = Socket.gethostname
63
-
64
- cs = "winmgmts:{impersonationLevel=impersonate}!//#{lhost}/root/cimv2"
65
- wmi = WIN32OLE.connect(cs)
66
-
67
- query = "select * from win32_pingstatus where address = '#{host}'"
68
-
69
- unless options.empty?
70
- options.each{ |key, value|
71
- if value.is_a?(String)
72
- query << " and #{key} = '#{value}'"
73
- else
74
- query << " and #{key} = #{value}"
75
- end
76
- }
77
- end
78
-
79
- status = Struct::PingStatus.new
80
-
81
- wmi.execquery(query).each{ |obj|
82
- status.address = obj.Address
83
- status.buffer_size = obj.BufferSize
84
- status.no_fragmentation = obj.NoFragmentation
85
- status.primary_address_resolution_status = obj.PrimaryAddressResolutionStatus
86
- status.protocol_address = obj.ProtocolAddress
87
- status.protocol_address_resolved = obj.ProtocolAddressResolved
88
- status.record_route = obj.RecordRoute
89
- status.reply_inconsistency = obj.ReplyInconsistency
90
- status.reply_size = obj.ReplySize
91
- status.resolve_address_names = obj.ResolveAddressNames
92
- status.response_time = obj.ResponseTime
93
- status.response_time_to_live = obj.ResponseTimeToLive
94
- status.route_record = obj.RouteRecord
95
- status.route_record_resolved = obj.RouteRecordResolved
96
- status.source_route = obj.SourceRoute
97
- status.source_route_type = obj.SourceRouteType
98
- status.status_code = obj.StatusCode
99
- status.timeout = obj.Timeout
100
- status.timestamp_record = obj.TimeStampRecord
101
- status.timestamp_record_address = obj.TimeStampRecordAddress
102
- status.timestamp_record_address_resolved = obj.TimeStampRecordAddressResolved
103
- status.timestamp_route = obj.TimeStampRoute
104
- status.time_to_live = obj.TimeToLive
105
- status.type_of_service = obj.TypeOfService
106
- }
107
-
108
- status.freeze # Read-only data
109
- end
110
-
111
- # Unlike Net::Ping::WMI#ping, this method returns true or false to
112
- # indicate whether or not the ping was successful.
113
- #
114
- def ping?(host = @host, options = {})
115
- ping(host, options).status_code == 0
116
- end
117
- end
118
- end
1
+ require File.join(File.dirname(__FILE__), 'ping')
2
+ require 'win32ole'
3
+
4
+ # The Net module serves as a namespace only.
5
+ #
6
+ module Net
7
+
8
+ # The Ping::WMI class encapsulates the Win32_PingStatus WMI class for
9
+ # MS Windows.
10
+ #
11
+ class Ping::WMI < Ping
12
+
13
+ PingStatus = Struct.new(
14
+ 'PingStatus',
15
+ :address,
16
+ :buffer_size,
17
+ :no_fragmentation,
18
+ :primary_address_resolution_status,
19
+ :protocol_address,
20
+ :protocol_address_resolved,
21
+ :record_route,
22
+ :reply_inconsistency,
23
+ :reply_size,
24
+ :resolve_address_names,
25
+ :response_time,
26
+ :response_time_to_live,
27
+ :route_record,
28
+ :route_record_resolved,
29
+ :source_route,
30
+ :source_route_type,
31
+ :status_code,
32
+ :timeout,
33
+ :timestamp_record,
34
+ :timestamp_record_address,
35
+ :timestamp_record_address_resolved,
36
+ :timestamp_route,
37
+ :time_to_live,
38
+ :type_of_service
39
+ )
40
+
41
+ # Unlike the ping method for other Ping subclasses, this version returns
42
+ # a PingStatus struct which contains various bits of information about
43
+ # the results of the ping itself, such as response time.
44
+ #
45
+ # In addition, this version allows you to pass certain options that are
46
+ # then passed on to the underlying WQL query. See the MSDN documentation
47
+ # on Win32_PingStatus for details.
48
+ #
49
+ # Examples:
50
+ #
51
+ # # Ping with no options
52
+ # Ping::WMI.ping('www.perl.com')
53
+ #
54
+ # # Ping with options
55
+ # Ping::WMI.ping('www.perl.com', :BufferSize => 64, :NoFragmentation => true)
56
+ #--
57
+ # The PingStatus struct is a wrapper for the Win32_PingStatus WMI class.
58
+ #
59
+ def ping(host = @host, options = {})
60
+ super(host)
61
+
62
+ lhost = Socket.gethostname
63
+
64
+ cs = "winmgmts:{impersonationLevel=impersonate}!//#{lhost}/root/cimv2"
65
+ wmi = WIN32OLE.connect(cs)
66
+
67
+ query = "select * from win32_pingstatus where address = '#{host}'"
68
+
69
+ unless options.empty?
70
+ options.each{ |key, value|
71
+ if value.is_a?(String)
72
+ query << " and #{key} = '#{value}'"
73
+ else
74
+ query << " and #{key} = #{value}"
75
+ end
76
+ }
77
+ end
78
+
79
+ status = Struct::PingStatus.new
80
+
81
+ wmi.execquery(query).each{ |obj|
82
+ status.address = obj.Address
83
+ status.buffer_size = obj.BufferSize
84
+ status.no_fragmentation = obj.NoFragmentation
85
+ status.primary_address_resolution_status = obj.PrimaryAddressResolutionStatus
86
+ status.protocol_address = obj.ProtocolAddress
87
+ status.protocol_address_resolved = obj.ProtocolAddressResolved
88
+ status.record_route = obj.RecordRoute
89
+ status.reply_inconsistency = obj.ReplyInconsistency
90
+ status.reply_size = obj.ReplySize
91
+ status.resolve_address_names = obj.ResolveAddressNames
92
+ status.response_time = obj.ResponseTime
93
+ status.response_time_to_live = obj.ResponseTimeToLive
94
+ status.route_record = obj.RouteRecord
95
+ status.route_record_resolved = obj.RouteRecordResolved
96
+ status.source_route = obj.SourceRoute
97
+ status.source_route_type = obj.SourceRouteType
98
+ status.status_code = obj.StatusCode
99
+ status.timeout = obj.Timeout
100
+ status.timestamp_record = obj.TimeStampRecord
101
+ status.timestamp_record_address = obj.TimeStampRecordAddress
102
+ status.timestamp_record_address_resolved = obj.TimeStampRecordAddressResolved
103
+ status.timestamp_route = obj.TimeStampRoute
104
+ status.time_to_live = obj.TimeToLive
105
+ status.type_of_service = obj.TypeOfService
106
+ }
107
+
108
+ status.freeze # Read-only data
109
+ end
110
+
111
+ # Unlike Net::Ping::WMI#ping, this method returns true or false to
112
+ # indicate whether or not the ping was successful.
113
+ #
114
+ def ping?(host = @host, options = {})
115
+ ping(host, options).status_code == 0
116
+ end
117
+ end
118
+ end
data/net-ping.gemspec CHANGED
@@ -1,38 +1,43 @@
1
- require 'rubygems'
2
- require 'rbconfig'
3
-
4
- Gem::Specification.new do |gem|
5
- gem.name = 'net-ping'
6
- gem.version = '1.4.1'
7
- gem.license = 'Artistic 2.0'
8
- gem.author = 'Daniel J. Berger'
9
- gem.email = 'djberg96@gmail.com'
10
- gem.homepage = 'http://www.rubyforge.org/projects/shards'
11
- gem.summary = 'A ping interface for Ruby.'
12
- gem.test_file = 'test/test_net_ping.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
-
16
- gem.rubyforge_project = 'shards'
17
- gem.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
18
-
19
- gem.add_development_dependency('test-unit', '>= 2.1.2')
20
- gem.add_development_dependency('fakeweb', '>= 1.3.0')
21
-
22
- # These dependencies are for Net::Ping::External
23
- if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
24
- gem.platform = Gem::Platform::CURRENT
25
- gem.add_dependency('windows-pr', '>= 1.0.8')
26
- gem.add_development_dependency('win32-security', '>= 1.0.8')
27
-
28
- if RUBY_VERSION.to_f < 1.9
29
- gem.add_dependency('win32-open3', '>= 0.3.1')
30
- end
31
- end
32
-
33
- gem.description = <<-EOF
34
- The net-ping library provides a ping interface for Ruby. It includes
35
- separate TCP, HTTP, ICMP, UDP, WMI (for Windows) and external ping
36
- classes.
37
- EOF
38
- end
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'net-ping'
6
+ spec.version = '1.5.3'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.author = 'Daniel J. Berger'
9
+ spec.email = 'djberg96@gmail.com'
10
+ spec.homepage = 'http://www.rubyforge.org/projects/shards'
11
+ spec.summary = 'A ping interface for Ruby.'
12
+ spec.test_file = 'test/test_net_ping.rb'
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
+
15
+ spec.rubyforge_project = 'shards'
16
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
17
+
18
+ spec.add_dependency('net-ldap', '~> 0.2.2')
19
+ spec.add_dependency('ffi', '>= 1.0.0')
20
+
21
+ spec.add_development_dependency('test-unit', '>= 2.1.2')
22
+ spec.add_development_dependency('fakeweb', '>= 1.3.0')
23
+ spec.add_development_dependency('fakeldap', '~> 0.0.1')
24
+
25
+ if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
26
+ spec.platform = Gem::Platform::CURRENT
27
+ spec.platform.cpu = 'universal'
28
+ spec.platform.version = nil
29
+
30
+ # Used primarily for icmp pings.
31
+ spec.add_development_dependency('win32-security', '>= 1.0.8')
32
+
33
+ if RUBY_VERSION.to_f < 1.9
34
+ spec.add_dependency('win32-open3', '>= 0.3.1')
35
+ end
36
+ end
37
+
38
+ spec.description = <<-EOF
39
+ The net-ping library provides a ping interface for Ruby. It includes
40
+ separate TCP, HTTP, LDAP, ICMP, UDP, WMI (for Windows) and external ping
41
+ classes.
42
+ EOF
43
+ end
@@ -1,37 +1,37 @@
1
- ######################################################################
2
- # test_net_ping.rb
3
- #
4
- # Test suite for all the Ping subclasses. Note that the Ping::ICMP
5
- # class test won't be run unless this is run as a privileged process.
6
- ######################################################################
7
- require 'test_net_ping_external'
8
- require 'test_net_ping_http'
9
- require 'test_net_ping_tcp'
10
- require 'test_net_ping_udp'
11
- require 'fakeweb'
12
-
13
- if File::ALT_SEPARATOR
14
- require 'win32/security'
15
- require 'windows/system_info'
16
- include Windows::SystemInfo
17
-
18
- if windows_version >= 6 && Win32::Security.elevated_security?
19
- require 'test_net_ping_icmp'
20
- end
21
- else
22
- if Process.euid == 0
23
- require 'test_net_ping_icmp'
24
- end
25
- end
26
-
27
- if File::ALT_SEPARATOR
28
- require 'test_net_ping_wmi'
29
- end
30
-
31
- class TC_Net_Ping < Test::Unit::TestCase
32
- def test_net_ping_version
33
- assert_equal('1.4.1', Net::Ping::VERSION)
34
- end
35
- end
36
-
37
- FakeWeb.allow_net_connect = false
1
+ ######################################################################
2
+ # test_net_ping.rb
3
+ #
4
+ # Test suite for all the Ping subclasses. Note that the Ping::ICMP
5
+ # class test won't be run unless this is run as a privileged process.
6
+ ######################################################################
7
+ require 'test_net_ping_external'
8
+ require 'test_net_ping_http'
9
+ require 'test_net_ping_tcp'
10
+ require 'test_net_ping_udp'
11
+ require 'fakeweb'
12
+
13
+ if File::ALT_SEPARATOR
14
+ require 'win32/security'
15
+ require 'windows/system_info'
16
+ include Windows::SystemInfo
17
+
18
+ if windows_version >= 6 && Win32::Security.elevated_security?
19
+ require 'test_net_ping_icmp'
20
+ end
21
+ else
22
+ if Process.euid == 0
23
+ require 'test_net_ping_icmp'
24
+ end
25
+ end
26
+
27
+ if File::ALT_SEPARATOR
28
+ require 'test_net_ping_wmi'
29
+ end
30
+
31
+ class TC_Net_Ping < Test::Unit::TestCase
32
+ def test_net_ping_version
33
+ assert_equal('1.5.2', Net::Ping::VERSION)
34
+ end
35
+ end
36
+
37
+ FakeWeb.allow_net_connect = false
@@ -1,121 +1,128 @@
1
- #########################################################################
2
- # test_net_ping_external.rb
3
- #
4
- # Test case for the Net::PingExternal class. Run this via the 'test' or
5
- # 'test:external' rake task.
6
- #########################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
11
- require 'net/ping/external'
12
-
13
- class TC_Net_Ping_External < Test::Unit::TestCase
14
- def setup
15
- @host = 'www.ruby-lang.org'
16
- @bogus = 'foo.bar.baz'
17
- @pe = Net::Ping::External.new(@host)
18
- @bad = Net::Ping::External.new(@bogus)
19
- end
20
-
21
- test "ping basic functionality" do
22
- assert_respond_to(@pe, :ping)
23
- end
24
-
25
- test "ping with no arguments" do
26
- assert_nothing_raised{ @pe.ping }
27
- end
28
-
29
- test "ping accepts a hostname" do
30
- assert_nothing_raised{ @pe.ping(@host) }
31
- end
32
-
33
- test "ping returns a boolean" do
34
- assert_boolean(@pe.ping)
35
- assert_boolean(@bad.ping)
36
- end
37
-
38
- test "ping? alias" do
39
- assert_respond_to(@pe, :ping?)
40
- assert_alias_method(@pe, :ping?, :ping)
41
- end
42
-
43
- test "pingecho alias" do
44
- assert_nothing_raised{ @pe.pingecho }
45
- assert_alias_method(@pe, :pingecho, :ping)
46
- end
47
-
48
- test "pinging a good host returns true" do
49
- assert_true(@pe.ping?)
50
- end
51
-
52
- test "pinging a bogus host returns false" do
53
- assert_false(@bad.ping?)
54
- end
55
-
56
- test "duration basic functionality" do
57
- assert_nothing_raised{ @pe.ping }
58
- assert_respond_to(@pe, :duration)
59
- assert_kind_of(Float, @pe.duration)
60
- end
61
-
62
- test "host getter basic functionality" do
63
- assert_respond_to(@pe, :host)
64
- assert_equal('www.ruby-lang.org', @pe.host)
65
- end
66
-
67
- test "host setter basic functionality" do
68
- assert_respond_to(@pe, :host=)
69
- assert_nothing_raised{ @pe.host = @bad }
70
- assert_equal(@bad, @pe.host)
71
- end
72
-
73
- test "port getter basic functionality" do
74
- assert_respond_to(@pe, :port)
75
- assert_equal(7, @pe.port)
76
- end
77
-
78
- test "port setter basic functionality" do
79
- assert_respond_to(@pe, :port=)
80
- assert_nothing_raised{ @pe.port = 90 }
81
- assert_equal(90, @pe.port)
82
- end
83
-
84
- test "timeout getter basic functionality" do
85
- assert_respond_to(@pe, :timeout)
86
- assert_equal(5, @pe.timeout)
87
- end
88
-
89
- test "timeout setter basic functionality" do
90
- assert_respond_to(@pe, :timeout=)
91
- assert_nothing_raised{ @pe.timeout = 30 }
92
- assert_equal(30, @pe.timeout)
93
- end
94
-
95
- test "exception method basic functionality" do
96
- assert_respond_to(@pe, :exception)
97
- assert_nil(@pe.exception)
98
- end
99
-
100
- test "pinging a bogus host stores exception data" do
101
- assert_nothing_raised{ @bad.ping? }
102
- assert_not_nil(@bad.exception)
103
- end
104
-
105
- test "pinging a good host results in no exception data" do
106
- assert_nothing_raised{ @pe.ping }
107
- assert_nil(@pe.exception)
108
- end
109
-
110
- test "warning basic functionality" do
111
- assert_respond_to(@pe, :warning)
112
- assert_nil(@pe.warning)
113
- end
114
-
115
- def teardown
116
- @host = nil
117
- @bogus = nil
118
- @pe = nil
119
- @bad = nil
120
- end
121
- end
1
+ #########################################################################
2
+ # test_net_ping_external.rb
3
+ #
4
+ # Test case for the Net::PingExternal class. Run this via the 'test' or
5
+ # 'test:external' rake task.
6
+ #########################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'net/ping/external'
12
+
13
+ class TC_Net_Ping_External < Test::Unit::TestCase
14
+ def setup
15
+ @host = 'localhost'
16
+ @bogus = 'foo.bar.baz'
17
+ @pe = Net::Ping::External.new(@host)
18
+ @bad = Net::Ping::External.new(@bogus)
19
+ end
20
+
21
+ test "ping basic functionality" do
22
+ assert_respond_to(@pe, :ping)
23
+ end
24
+
25
+ test "ping with no arguments" do
26
+ assert_nothing_raised{ @pe.ping }
27
+ end
28
+
29
+ test "ping accepts a hostname" do
30
+ assert_nothing_raised{ @pe.ping(@host) }
31
+ end
32
+
33
+ test "ping returns a boolean" do
34
+ assert_boolean(@pe.ping)
35
+ assert_boolean(@bad.ping)
36
+ end
37
+
38
+ test "ping? alias" do
39
+ assert_respond_to(@pe, :ping?)
40
+ assert_alias_method(@pe, :ping?, :ping)
41
+ end
42
+
43
+ test "pingecho alias" do
44
+ assert_nothing_raised{ @pe.pingecho }
45
+ assert_alias_method(@pe, :pingecho, :ping)
46
+ end
47
+
48
+ test "pinging a good host returns true" do
49
+ assert_true(@pe.ping?)
50
+ end
51
+
52
+ test "pinging a bogus host returns false" do
53
+ assert_false(@bad.ping?)
54
+ end
55
+
56
+ test "duration basic functionality" do
57
+ assert_nothing_raised{ @pe.ping }
58
+ assert_respond_to(@pe, :duration)
59
+ assert_kind_of(Float, @pe.duration)
60
+ end
61
+
62
+ test "duration is unset if a bad ping follows a good ping" do
63
+ assert_nothing_raised{ @pe.ping }
64
+ assert_not_nil(@pe.duration)
65
+ assert_false(@pe.ping?(@bogus))
66
+ assert_nil(@pe.duration)
67
+ end
68
+
69
+ test "host getter basic functionality" do
70
+ assert_respond_to(@pe, :host)
71
+ assert_equal('localhost', @pe.host)
72
+ end
73
+
74
+ test "host setter basic functionality" do
75
+ assert_respond_to(@pe, :host=)
76
+ assert_nothing_raised{ @pe.host = @bad }
77
+ assert_equal(@bad, @pe.host)
78
+ end
79
+
80
+ test "port getter basic functionality" do
81
+ assert_respond_to(@pe, :port)
82
+ assert_equal(7, @pe.port)
83
+ end
84
+
85
+ test "port setter basic functionality" do
86
+ assert_respond_to(@pe, :port=)
87
+ assert_nothing_raised{ @pe.port = 90 }
88
+ assert_equal(90, @pe.port)
89
+ end
90
+
91
+ test "timeout getter basic functionality" do
92
+ assert_respond_to(@pe, :timeout)
93
+ assert_equal(5, @pe.timeout)
94
+ end
95
+
96
+ test "timeout setter basic functionality" do
97
+ assert_respond_to(@pe, :timeout=)
98
+ assert_nothing_raised{ @pe.timeout = 30 }
99
+ assert_equal(30, @pe.timeout)
100
+ end
101
+
102
+ test "exception method basic functionality" do
103
+ assert_respond_to(@pe, :exception)
104
+ assert_nil(@pe.exception)
105
+ end
106
+
107
+ test "pinging a bogus host stores exception data" do
108
+ assert_nothing_raised{ @bad.ping? }
109
+ assert_not_nil(@bad.exception)
110
+ end
111
+
112
+ test "pinging a good host results in no exception data" do
113
+ assert_nothing_raised{ @pe.ping }
114
+ assert_nil(@pe.exception)
115
+ end
116
+
117
+ test "warning basic functionality" do
118
+ assert_respond_to(@pe, :warning)
119
+ assert_nil(@pe.warning)
120
+ end
121
+
122
+ def teardown
123
+ @host = nil
124
+ @bogus = nil
125
+ @pe = nil
126
+ @bad = nil
127
+ end
128
+ end