sys-host 0.6.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,115 @@
1
+ == 0.6.1 - 18-Nov-2008
2
+ * Added the host_id method for Windows, which just returns the MAC address.
3
+ * Fixed an issue in the Host.ip_addr method for MS Windows where multiple ip
4
+ addresses might not be handled properly. Thanks go to Murmansk Manny for the
5
+ spot and patch.
6
+ * Updated the gemspec to include all .c and .h files now so that it should
7
+ successfully build and install on all Unix platforms.
8
+ * Rakefile fix for MS Windows for the install task.
9
+ * The test file is now "test_sys_host.rb".
10
+
11
+ == 0.6.0 - 8-Jun-2007
12
+ * Now supports OS X!
13
+ * Added the Host.host_id class method.
14
+ * Bug/warning fix for OS X.
15
+ * HostError is now Host::Error.
16
+ * Added a Rakefile, including tasks for installation and testing.
17
+ * Fixed the gemspec (I hope).
18
+ * Lots of internal reorganization, including the removal of the install.rb
19
+ file. That's handled by the Rakefile.
20
+
21
+ == 0.5.2 - 27-Jun-2006
22
+ * Added the Host.info method for Linux.
23
+
24
+ == 0.5.1 - 3-Mar-2006
25
+ * The Host.info method is now supported on Solaris.
26
+ * Moved project to RubyForge.
27
+ * Replaced INSTALL with README.
28
+ * Made documentation rdoc friendly.
29
+
30
+ == 0.5.0 - 3-Jul-2004
31
+ * Replaced Windows C extension with pure Ruby version, using WMI + OLE.
32
+ * Added an additional class method called 'info' that returns a HostInfo
33
+ struct. Currently on Windows only.
34
+ * Removed the block form of Host.ip_addr. It now simply returns an Array.
35
+ * Renamed and revamped test suite.
36
+ * Moved test.rb to doc/examples
37
+ * Removed the host.html file.
38
+ * Replaced previous exception classes with a single exception class,
39
+ HostError, and moved it under the Sys module namespace.
40
+
41
+ == 0.4.0 - 15-Jun-2003
42
+ * Added MS Windows support
43
+ * Modified extconf.rb file - generic test script now in its own file
44
+ (test/test.rb) and the dynamic rd2 stuff was removed, in addition to proper
45
+ handling for MS Windows
46
+ * rd2, txt and html docs now included by default
47
+ * Removed VERSION() class method (use the constant instead)
48
+ * Added a universal constants.h file to store VERSION info, etc, that
49
+ is common to all source files.
50
+ * Added LICENSE info
51
+
52
+ == 0.3.4 - 3-Apr-2003
53
+ * Fixed a header include issue for solaris systems that don't
54
+ define inet_ntop().
55
+
56
+ == 0.3.3 * 24-Mar-2003
57
+ * If inet_ntop() is not defined, now falls back to inet_ntoa().
58
+
59
+ == 0.3.2 - 14-Mar-2003
60
+ * Added a VERSION constant
61
+ * Modified extconf.rb script, including a bugfix for solaris
62
+ * Added a test suite (for those with testunit installed)
63
+ * Removed the sys-uname requirement
64
+ * Changelog and Manifest are now CHANGES and MANIFEST, respectively
65
+ * Minor internal layout changes
66
+ * rd2 documentation removed from C source files and put into 'doc'
67
+ directory
68
+
69
+ == 0.3.1 - 6-Jan-2003
70
+ * Fix to make code C89 compliant so that older compilers don't choke.
71
+ * Added a VERSION class method
72
+ * Added a copyright notice
73
+ * Moved README into doc/host.txt
74
+ * Minor doc changes
75
+ * Fixed extconf.rb file to include socket lib for Solaris. This was
76
+ in 0.2.0 and was mistakenly left out of 0.3.0.
77
+
78
+ == 0.3.0 - 28-Oct-2002
79
+ * Reentrant (thread-safe) support added for ip_addr() method (for Linux,
80
+ FreeBSD and Solaris currently).
81
+ * The file layout changed so that each platform has its own source file.
82
+ This was done because different platforms have different implementations
83
+ of gethostbyname_r(), if they have them at all. Some platforms (e.g.
84
+ FreeBSD) use a different function altogether.
85
+ * The file generic.c is used to create the source if the platform is not
86
+ currently supported, or if gethostbyname_r() isn't found.
87
+ * The FreeBSD implementation uses getipnodebyname() instead of
88
+ gethostbyname(), if possible. According to the man page, it's thread
89
+ safe.
90
+ * Modifications to the extconf.rb file based on the above changes.
91
+ * Added a default value of 16 for INET_ADDRSTRLEN.
92
+ * Added a README file.
93
+
94
+ == 0.2.0 - 1-Sep-2002
95
+ * Added HostException and HostAddressException classes. These are raised
96
+ in the event the gethostname or gethostbyname call fails, respectively.
97
+ * Removed some unnecessary (and warning-causing) free calls.
98
+ * Added an INSTALL file (installation instructions removed from core doc).
99
+
100
+ == 0.1.2 - 9-Aug-2002
101
+ * Got the BSD support working properly this time. Thanks to Sean
102
+ Chittenden for providing BSD access.
103
+
104
+ == 0.1.1 - 21-Jun-2002
105
+ * Fixed a bug that would cause the ip_addr to segfault on some
106
+ operating systems. Apparently ,trying to free memory on a
107
+ null pointer is a bad thing. Hey, Solaris didn't complain!
108
+ Thanks go to Han Holl for the spot.
109
+ * On *BSD systems the 'netinet/in.h' file is now included (via
110
+ the makefile). Thanks go to Magnus Stahre for the spot and
111
+ the fix.
112
+ * Changed the version number to be more "ruby compliant"
113
+
114
+ == 0.01 * 11-Jun-2002
115
+ * First release!
data/MANIFEST ADDED
@@ -0,0 +1,15 @@
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * sys-host.gemspec
6
+ * doc/host.txt
7
+ * examples/host_test.rb
8
+ * ext/constants.h
9
+ * ext/extconf.rb
10
+ * ext/bsd/bsd.c
11
+ * ext/generic/generic.c
12
+ * ext/linux/linux.c
13
+ * ext/sunos/sunos.c
14
+ * lib/sys/windows.rb
15
+ * test/test_sys_host.rb
data/README ADDED
@@ -0,0 +1,26 @@
1
+ = Prerequisites
2
+ Ruby 1.8.0 or later.
3
+ Ruby 1.8.2 or later preferred on Windows.
4
+
5
+ = Synopsis
6
+ require 'sys/host'
7
+ include Sys
8
+
9
+ p Host.hostname
10
+ p Host.ip_addr
11
+
12
+ Host.info{ |h|
13
+ p h
14
+ }
15
+
16
+ = Installation
17
+ == Standard (non-gem) installation
18
+ rake test (optional)
19
+ rake install
20
+
21
+ == Gem Installation
22
+ rake test (optional)
23
+ rake install_gem
24
+
25
+ = Documentation
26
+ See the doc/host.txt file for more information.
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+ include Config
6
+
7
+ desc "Clean the build files for the sys-host source for UNIX systems"
8
+ task :clean do
9
+ Dir.chdir('ext') do
10
+ unless RUBY_PLATFORM.match('mswin')
11
+ sh 'make distclean' if File.exists?('host.o')
12
+ FileUtils.rm_rf('host.c') if File.exists?('host.c')
13
+ FileUtils.rm_rf('sys') if File.exists?('sys')
14
+ end
15
+ end
16
+ FileUtils.rm_rf('sys') if File.exists?('sys')
17
+ end
18
+
19
+ desc "Build the sys-host package on UNIX systems (but don't install it)"
20
+ task :build => [:clean] do
21
+ Dir.chdir('ext') do
22
+ ruby 'extconf.rb'
23
+ sh 'make'
24
+ build_file = 'host.' + Config::CONFIG['DLEXT']
25
+ Dir.mkdir('sys') unless File.exists?('sys')
26
+ FileUtils.cp(build_file, 'sys')
27
+ end
28
+ end
29
+
30
+ desc "Run the example program"
31
+ task :example => [:build] do
32
+ ruby 'host_test.rb'
33
+ end
34
+
35
+ if CONFIG['host_os'].match('mswin')
36
+ desc "Install the sys-host package (non-gem)"
37
+ task :install do
38
+ install_dir = File.join(CONFIG['sitelibdir'], 'sys')
39
+ install_file = File.join(install_dir, 'host.rb')
40
+ Dir.mkdir(install_dir) unless File.exists?(install_dir)
41
+ FileUtils.cp('lib/sys/windows.rb', install_file, :verbose => true)
42
+ end
43
+ else
44
+ desc "Install the sys-host package (non-gem)"
45
+ task :install => [:build] do
46
+ Dir.chdir('ext') do
47
+ sh 'make install'
48
+ end
49
+ end
50
+ end
51
+
52
+ desc "Install the sys-host package as a gem"
53
+ task :install_gem do
54
+ ruby 'sys-host.gemspec'
55
+ file = Dir["sys-host*.gem"].last
56
+ sh "gem install #{file}"
57
+ end
58
+
59
+ desc "Run the example sys-host program"
60
+ task :example => [:build] do
61
+ Dir.mkdir('sys') unless File.exists?('sys')
62
+ if CONFIG['host_os'].match('mswin')
63
+ FileUtils.cp('lib/sys/windows.rb', 'lib/sys/host.rb')
64
+ ruby '-Ilib examples/host_test.rb'
65
+ else
66
+ ruby '-Iext examples/host_test.rb'
67
+ end
68
+ end
69
+
70
+ Rake::TestTask.new do |t|
71
+ if CONFIG['host_os'].match('mswin')
72
+ FileUtils.cp('lib/sys/windows.rb', 'lib/sys/host.rb')
73
+ else
74
+ task :test => :build
75
+ t.libs << 'ext'
76
+ t.libs.delete('lib')
77
+ end
78
+ end
data/doc/host.txt ADDED
@@ -0,0 +1,88 @@
1
+ == Description
2
+ Provides hostname and ip address information for a given host.
3
+
4
+ == Synopsis
5
+ require 'sys/host'
6
+ include Sys
7
+
8
+ p Host.hostname
9
+ p Host.ip_addr
10
+
11
+ # Some platforms
12
+ Host.info{ |h|
13
+ p h
14
+ }
15
+
16
+ == Constants
17
+ VERSION
18
+ Returns the current version number of this library (as a string)
19
+
20
+ == Class Methods
21
+ Host.hostname
22
+ Returns the hostname of the current host. This may or not return
23
+ the FQDN, depending on your system.
24
+
25
+ Host.ip_addr
26
+ Returns a list of IP addresses for the current host (yes, it is
27
+ possible to have more than one).
28
+
29
+ Host.info(host=localhost)
30
+ Host.info(host=localhost){ |h| ... }
31
+ Yields a HostInfo struct for each network adapter on 'host', or an array
32
+ of HostInfo struct's in non-block form. The exact members of this struct
33
+ vary depending on your platform.
34
+
35
+ == Exception Classes
36
+ Host::Error < StandardError
37
+ Raised in the event of a failure for any of the class methods provided
38
+ with this library. Generally speaking, it means there was a failure in
39
+ the underlying gethostname() or gethostbyname() calls.
40
+
41
+ == Future Plans
42
+ Add support for IPV6. This will be difficult unless I have access to a
43
+ system on an IPV6 network. Any help on this front appreciated.
44
+
45
+ == Notes
46
+ The Windows version of this library uses OLE + WMI. The Host.info method
47
+ returns considerably more information than the *nix versions of this
48
+ library.
49
+
50
+ == Comments and Questions
51
+ Please direct all comments and/or questions to one of the Forums on the
52
+ project home page at http://www.rubyforge.org/projects/sysutils.
53
+
54
+ == Known Bugs
55
+ None that I'm aware of.
56
+
57
+ Please log any bugs on the project home page at
58
+ http://www.rubyforge.org/projects/sysutils
59
+
60
+ == Acknowledgements
61
+ Thanks go to Mike Hall, Guy Decoux, and Matz for their help with
62
+ C extensions in general.
63
+
64
+ Thanks also go to Richard Stevens for his excellent Unix programming
65
+ books.
66
+
67
+ == License
68
+ Ruby's
69
+
70
+ == Copyright
71
+ Copyright 2002-2008, Daniel J. Berger, djberg96 at gmail dot com
72
+
73
+ All Rights Reserved. This module is free software. It may be used,
74
+ redistributed and/or modified under the same terms as Ruby itself.
75
+
76
+ == Warranty
77
+ This library is provided "as is" and without any express or
78
+ implied warranties, including, without limitation, the implied
79
+ warranties of merchantability and fitness for a particular purpose.
80
+
81
+ == Author
82
+ Daniel J. Berger
83
+ djberg96 at gmail dot com
84
+ imperator on IRC (freenode)
85
+
86
+ == See Also
87
+ gethostbyname, gethostbyname_r, gethostname, hostname (Unix)
88
+ WMI, OLE (Windows)
data/lib/sys/host.rb ADDED
@@ -0,0 +1,272 @@
1
+ require 'win32ole'
2
+ require 'socket'
3
+ require 'time'
4
+
5
+ module Sys
6
+ class Host
7
+ class Error < StandardError; end
8
+
9
+ VERSION = '0.6.1'
10
+
11
+ fields = %w/
12
+ arp_always_source_route?
13
+ arp_use_ether_snap?
14
+ caption
15
+ database_path
16
+ dead_gw_detect_enabled?
17
+ default_ip_gateway
18
+ default_tos
19
+ default_ttl
20
+ description
21
+ dhcp_enabled?
22
+ dhcp_lease_expires
23
+ dhcp_lease_obtained
24
+ dhcp_server
25
+ dns_domain
26
+ dns_domain_suffix_search_order
27
+ dns_enabled_for_wins_resolution?
28
+ dns_host_name
29
+ dns_server_search_order
30
+ domain_dns_registration_enabled?
31
+ forward_buffer_memory
32
+ full_dns_registration_enabled?
33
+ gateway_cost_metric
34
+ igmp_level
35
+ index
36
+ ip_address
37
+ ip_connection_metric
38
+ ip_enabled?
39
+ ip_filter_security_enabled?
40
+ ip_port_security_enabled?
41
+ ip_sec_permit_ip_protocols
42
+ ip_sec_permit_tcp_ports
43
+ ip_sec_permit_udp_ports
44
+ ip_subnet
45
+ ip_use_zero_broadcast
46
+ ipx_address
47
+ ipx_enabled?
48
+ ipx_frame_type
49
+ ipx_media_type
50
+ ipx_network_number
51
+ ipx_virtual_net_number
52
+ keep_alive_interval
53
+ keep_alive_time
54
+ mac_address
55
+ mtu
56
+ num_forward_packets
57
+ pmtubh_detect_enabled?
58
+ pmtu_discovery_enabled?
59
+ service_name
60
+ setting_id
61
+ tcpip_netbios_options
62
+ tcp_max_connect_retransmissions
63
+ tcp_max_data_retransmissions
64
+ tcp_num_connections
65
+ tcp_use_rfc1122_urgent_pointer?
66
+ tcp_window_size
67
+ wins_enable_lm_hosts_lookup?
68
+ wins_host_lookup_file
69
+ wins_primary_server
70
+ wins_scope_id
71
+ wins_secondary_server
72
+ /
73
+
74
+ HostInfo = Struct.new("HostInfo", *fields)
75
+
76
+ # Yields a HostInfo struct for each network adapter on 'host', or an array
77
+ # of HostInfo struct's in non-block form. The exact members of this struct
78
+ # vary depending on your platform.
79
+ #
80
+ def self.info(host=Socket.gethostname)
81
+ array = [] unless block_given?
82
+ cs = "winmgmts://#{host}/root/cimv2"
83
+
84
+ begin
85
+ wmi = WIN32OLE.connect(cs)
86
+ rescue WIN32OLERuntimeError => err
87
+ raise Error, err
88
+ else
89
+ query = "
90
+ select * from Win32_NetworkAdapterConfiguration
91
+ where IPEnabled = True
92
+ "
93
+ wmi.ExecQuery(query).each{ |nic|
94
+ if nic.DHCPLeaseExpires
95
+ dhcp_expires = Time.parse(nic.DHCPLeaseExpires.split('.')[0])
96
+ else
97
+ dhcp_expires = nil
98
+ end
99
+
100
+ if nic.DHCPLeaseObtained
101
+ dhcp_lease_obtained = Time.parse(nic.DHCPLeaseObtained.split('.')[0])
102
+ else
103
+ dhcp_lease_obtained = nil
104
+ end
105
+
106
+ igmp_level = nil
107
+ case nic.IGMPLevel
108
+ when 0
109
+ igmp_level = "None"
110
+ when 1
111
+ igmp_level = "IP"
112
+ when 2
113
+ igmp_level = "IP & IGMP"
114
+ end
115
+
116
+ ipx_frame_type = nil
117
+ case nic.IPXFrameType
118
+ when 0
119
+ ipx_frame_type = "Ethernet II"
120
+ when 1
121
+ ipx_frame_type = "Ethernet 802.3"
122
+ when 2
123
+ ipx_frame_type = "Ethernet 802.2"
124
+ when 3
125
+ ipx_frame_type = "Ethernet SNAP"
126
+ when 255
127
+ ipx_frame_type = "AUTO"
128
+ end
129
+
130
+ ipx_media_type = nil
131
+ case nic.IPXMediaType
132
+ when 0
133
+ ipx_media_type = "Ethernet"
134
+ when 1
135
+ ipx_media_type = "Token Ring"
136
+ when 2
137
+ ipx_media_type = "FDDI"
138
+ when 8
139
+ ipx_media_type = "ARCNET"
140
+ end
141
+
142
+ tcpip_netbios_options = nil
143
+ case nic.TcpipNetbiosOptions
144
+ when 0
145
+ tcpip_netbios_options = "EnableNetbiosViaDhcp"
146
+ when 1
147
+ tcpip_netbios_options = "EnableNetbios"
148
+ when 2
149
+ tcpip_netbios_options = "DisableNetbios"
150
+ end
151
+
152
+ struct = HostInfo.new(
153
+ nic.ArpAlwaysSourceRoute,
154
+ nic.ArpUseEtherSNAP,
155
+ nic.Caption,
156
+ nic.DatabasePath,
157
+ nic.DeadGWDetectEnabled,
158
+ nic.DefaultIPGateway,
159
+ nic.DefaultTOS,
160
+ nic.DefaultTTL,
161
+ nic.Description,
162
+ nic.DHCPEnabled,
163
+ dhcp_expires,
164
+ dhcp_lease_obtained,
165
+ nic.DHCPServer,
166
+ nic.DNSDomain,
167
+ nic.DNSDomainSuffixSearchOrder,
168
+ nic.DNSEnabledForWINSResolution,
169
+ nic.DNSHostName,
170
+ nic.DNSServerSearchOrder,
171
+ nic.DomainDNSRegistrationEnabled,
172
+ nic.ForwardBufferMemory,
173
+ nic.FullDNSRegistrationEnabled,
174
+ nic.GatewayCostMetric,
175
+ igmp_level,
176
+ nic.Index,
177
+ nic.IpAddress,
178
+ nic.IPConnectionMetric,
179
+ nic.IPEnabled,
180
+ nic.IPFilterSecurityEnabled,
181
+ nic.IPPortSecurityEnabled,
182
+ nic.IPSecPermitIPProtocols,
183
+ nic.IPSecPermitTCPPorts,
184
+ nic.IPSecPermitUDPPorts,
185
+ nic.IPSubnet,
186
+ nic.IPUseZeroBroadcast,
187
+ nic.IPXAddress,
188
+ nic.IPXEnabled,
189
+ ipx_frame_type,
190
+ ipx_media_type,
191
+ nic.IPXNetworkNumber,
192
+ nic.IPXVirtualNetNumber,
193
+ nic.KeepAliveInterval,
194
+ nic.KeepAliveTime,
195
+ nic.MacAddress,
196
+ nic.MTU,
197
+ nic.NumForwardPackets,
198
+ nic.PMTUBHDetectEnabled,
199
+ nic.PMTUDiscoveryEnabled,
200
+ nic.ServiceName,
201
+ nic.SettingID,
202
+ tcpip_netbios_options,
203
+ nic.TcpMaxConnectRetransmissions,
204
+ nic.TcpMaxDataRetransmissions,
205
+ nic.TcpNumConnections,
206
+ nic.TcpUseRFC1122UrgentPointer,
207
+ nic.TcpWindowSize,
208
+ nic.WINSEnableLMHostsLookup,
209
+ nic.WINSHostLookupFile,
210
+ nic.WINSPrimaryServer,
211
+ nic.WINSScopeID,
212
+ nic.WINSSecondaryServer
213
+ )
214
+
215
+ if block_given?
216
+ yield struct
217
+ else
218
+ array << struct
219
+ end
220
+ }
221
+ end
222
+
223
+ block_given? ? nil : array
224
+ end
225
+
226
+ # Returns the hostname of the current host. This may or not return
227
+ # the FQDN, depending on your system.
228
+ #
229
+ def self.hostname
230
+ host = nil
231
+ begin
232
+ wmi = WIN32OLE.connect("winmgmts://")
233
+ rescue WIN32OLERuntimeError => e
234
+ raise Error, e
235
+ else
236
+ query = "
237
+ select * from Win32_NetworkAdapterConfiguration
238
+ where IPEnabled = True
239
+ "
240
+ wmi.ExecQuery(query).each{ |nic|
241
+ host = nic.DNSHostName
242
+ break
243
+ }
244
+ end
245
+ host
246
+ end
247
+
248
+ # Returns a list of unique IP addresses for the current host.
249
+ #
250
+ def self.ip_addr
251
+ ip_addrs = []
252
+ begin
253
+ wmi = WIN32OLE.connect("winmgmts://")
254
+ rescue WIN32OLERuntimeError => e
255
+ raise Error, e
256
+ else
257
+ query = "
258
+ select * from Win32_NetworkAdapterConfiguration
259
+ where IPEnabled = True
260
+ "
261
+ wmi.ExecQuery(query).each{ |nic| ip_addrs << nic.IPAddress }
262
+ end
263
+ ip_addrs.flatten.uniq
264
+ end
265
+
266
+ # Returns the host id (mac address) of the current host.
267
+ #
268
+ def self.host_id
269
+ info[0].mac_address
270
+ end
271
+ end
272
+ end
data/sys-host.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+ include Config
4
+
5
+ spec = Gem::Specification.new do |gem|
6
+ gem.name = 'sys-host'
7
+ gem.version = '0.6.1'
8
+ gem.author = 'Daniel J. Berger'
9
+ gem.email = 'djberg96@gmail.com'
10
+ gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
11
+ gem.platform = Gem::Platform::RUBY
12
+ gem.summary = 'Provides hostname and ip address info for a given host'
13
+ gem.description = 'Provides hostname and ip address info for a given host'
14
+ gem.test_file = 'test/test_sys_host.rb'
15
+ gem.has_rdoc = true
16
+ gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
17
+ gem.rubyforge_project = 'sysutils'
18
+ files = Dir['doc/*'] + Dir['test/*'] + Dir['[A-Z]*']
19
+ files.delete_if{ |item| item.include?('CVS') }
20
+ gem.files = files
21
+
22
+ gem.add_dependency('test-unit', '>= 2.0.0')
23
+
24
+ if CONFIG['host_os'] =~ /mswin/
25
+ File.rename('lib/sys/windows.rb', 'lib/sys/host.rb')
26
+ gem.required_ruby_version = '>= 1.8.2'
27
+ gem.files += ['lib/sys/host.rb']
28
+ gem.platform = Gem::Platform::CURRENT
29
+ else
30
+ gem.required_ruby_version = '>= 1.8.0'
31
+ gem.files += Dir["ext/**/*.{c,h}"]
32
+ gem.extensions = ['ext/extconf.rb']
33
+ gem.extra_rdoc_files += Dir["ext/**/*.c"]
34
+ end
35
+ end
36
+
37
+ if $0 == __FILE__
38
+ Gem::Builder.new(spec).build
39
+ end
@@ -0,0 +1,95 @@
1
+ ###########################################################################
2
+ # test_sys_host.rb
3
+ #
4
+ # Test suite for sys-host, all platforms. You should run these tests via
5
+ # the 'rake test' task.
6
+ ###########################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'sys/host'
11
+ require 'test/unit'
12
+ require 'rbconfig'
13
+ include Config
14
+ include Sys
15
+
16
+ class TC_Sys_Host < Test::Unit::TestCase
17
+ def self.startup
18
+ if CONFIG['host_os'] =~ /mswin|solaris|linux|bsd|mach|darwin|osx/i
19
+ @@info_supported = true
20
+ else
21
+ @@info_supported = false
22
+ end
23
+
24
+ @@windows = CONFIG['host_os'].match('mswin')
25
+ end
26
+
27
+ def test_version
28
+ assert_equal('0.6.1', Host::VERSION)
29
+ end
30
+
31
+ def test_hostname_basic
32
+ assert_respond_to(Host, :hostname)
33
+ assert_nothing_raised{ Host.hostname }
34
+ end
35
+
36
+ def test_hostname
37
+ assert_kind_of(String, Host.hostname)
38
+ assert_equal(`hostname`.chomp, Host.hostname) # sanity check
39
+ end
40
+
41
+ def test_hostname_expected_errors
42
+ assert_raise(ArgumentError){ Host.hostname(true) }
43
+ end
44
+
45
+ def test_ip_addr_basic
46
+ assert_respond_to(Host, :ip_addr)
47
+ assert_nothing_raised{ Host.ip_addr }
48
+ end
49
+
50
+ def test_ip_addr
51
+ assert_kind_of(Array, Host.ip_addr)
52
+ assert_kind_of(String, Host.ip_addr.first)
53
+ end
54
+
55
+ def test_ip_addr_expected_errors
56
+ assert_raise(ArgumentError){ Host.ip_addr(true) }
57
+ end
58
+
59
+ def test_host_id_basic
60
+ assert_respond_to(Host, :host_id)
61
+ assert_nothing_raised{ Host.host_id }
62
+ end
63
+
64
+ def test_host_id
65
+ type = @@windows ? String : Integer
66
+ assert_kind_of(type, Host.host_id)
67
+ end
68
+
69
+ def test_host_id_expected_errors
70
+ assert_raise(ArgumentError){ Host.host_id(true) }
71
+ end
72
+
73
+ def test_info_basic
74
+ omit_unless(@@info_supported, 'info test skipped on this platform')
75
+ assert_respond_to(Host, :info)
76
+ assert_nothing_raised{ Host.info }
77
+ end
78
+
79
+ def test_info
80
+ omit_unless(@@info_supported, 'info test skipped on this platform')
81
+ assert_kind_of(Array, Host.info)
82
+ assert_kind_of(Struct::HostInfo, Host.info.first)
83
+ assert_nil(Host.info{ })
84
+ end
85
+
86
+ def test_info_high_iteration
87
+ omit_unless(@@info_supported, 'info test skipped on this platform')
88
+ assert_nothing_raised{ 100.times{ Host.info } }
89
+ end
90
+
91
+ def self.shutdown
92
+ @@info_supported = nil
93
+ @@windows = nil
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys-host
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: x86-mswin32-60
6
+ authors:
7
+ - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ version:
25
+ description: Provides hostname and ip address info for a given host
26
+ email: djberg96@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - CHANGES
33
+ - README
34
+ - MANIFEST
35
+ files:
36
+ - doc/host.txt
37
+ - test/test_sys_host.rb
38
+ - CHANGES
39
+ - doc
40
+ - examples
41
+ - ext
42
+ - lib
43
+ - MANIFEST
44
+ - Rakefile
45
+ - README
46
+ - sys-host.gemspec
47
+ - test
48
+ - lib/sys/host.rb
49
+ has_rdoc: true
50
+ homepage: http://www.rubyforge.org/projects/sysutils
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.8.2
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: sysutils
71
+ rubygems_version: 1.3.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: Provides hostname and ip address info for a given host
75
+ test_files:
76
+ - test/test_sys_host.rb