net-ping 2.2.0 → 3.0.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.
- checksums.yaml +4 -4
- data/CHANGES +16 -0
- data/Gemfile +16 -2
- data/Gemfile.lock +9 -1
- data/README.md +12 -3
- data/Rakefile +7 -0
- data/lib/net/ping/icmp.rb +9 -1
- data/lib/net/ping/tcp.rb +31 -15
- data/lib/net/ping/udp.rb +26 -5
- data/lib/net/ping/version.rb +1 -1
- data/lib/net/ping/wmi.rb +8 -1
- data/lib/net/ping.rb +6 -1
- data/net-ping.gemspec +2 -3
- data/sig/net/ping/external.rbs +13 -0
- data/sig/net/ping/http.rbs +41 -0
- data/sig/net/ping/icmp.rbs +28 -0
- data/sig/net/ping/ping.rbs +25 -0
- data/sig/net/ping/tcp.rbs +19 -0
- data/sig/net/ping/udp.rbs +19 -0
- data/sig/net/ping/version.rbs +5 -0
- data/sig/net/ping/wmi.rbs +63 -0
- data/test/test_net_ping.rb +1 -0
- data/test/test_net_ping_lib.rb +28 -0
- data/test/test_net_ping_udp.rb +27 -0
- metadata +12 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 615dc26b8e3f3946e27edd9d77a5db989cd7dc61acef84347ffa9bce3608bb4c
|
|
4
|
+
data.tar.gz: 067abe30201a7b58b738f1f6bf2a594c71a16489f4d4cace8bfa750e9c0e192a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0049c0226fb551554f816c8a824a8784107ed62af88ce5b7d00491db35505b21f0e62226afbcfcfa92d6fab58768f46c12289beeca9ff1a6b91941bf1c748ff0'
|
|
7
|
+
data.tar.gz: b4ca3000e0abb199a2209985d745708c35f62cfef2ca18ca0071b3d880c3e81160d99bb26af9b4f296934b343c889f09e6fa192ffa303da12fbd0f10e4469cfa
|
data/CHANGES
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
== 3.0.0 - 01-Nov-2026
|
|
2
|
+
* Raise the minimum supported Ruby version from 1.9.3 to 2.7, matching the
|
|
3
|
+
lowest version covered by CI. This is a breaking change for users on
|
|
4
|
+
older Rubies [#53](https://github.com/eitoball/net-ping/pull/53).
|
|
5
|
+
* Add JRuby support: fix TCP ping's handling of refused connections, make
|
|
6
|
+
UDP ping's timeout work on JRuby, and use win32ole-ffi for WMI pings on
|
|
7
|
+
JRuby. JRuby 10.0/10.1 are now covered by CI
|
|
8
|
+
[#53](https://github.com/eitoball/net-ping/pull/53).
|
|
9
|
+
* `require 'net/ping'` on Windows now warns instead of raising when
|
|
10
|
+
win32ole or win32-security is missing
|
|
11
|
+
[#53](https://github.com/eitoball/net-ping/pull/53).
|
|
12
|
+
* Drop pry-byebug from the gem's development dependencies
|
|
13
|
+
[#53](https://github.com/eitoball/net-ping/pull/53).
|
|
14
|
+
* Add RBS type definitions under sig/
|
|
15
|
+
[#54](https://github.com/eitoball/net-ping/pull/54).
|
|
16
|
+
|
|
1
17
|
== 2.2.0 - 22-Sep-2026
|
|
2
18
|
* Add support for HTTP to ping URLs requiring a query parameter, carrying
|
|
3
19
|
forward #25 by Kenneth Perry (@thothonegan)
|
data/Gemfile
CHANGED
|
@@ -2,7 +2,21 @@ source 'https://rubygems.org'
|
|
|
2
2
|
gemspec
|
|
3
3
|
gem 'win32-security', '>= 0.2.0' if Gem.win_platform?
|
|
4
4
|
|
|
5
|
-
# No longer a default gem as of Ruby 4.0
|
|
6
|
-
|
|
5
|
+
# Used by the WMI ping class. No longer a default gem as of Ruby 4.0, and
|
|
6
|
+
# win32ole's C extension does not build on JRuby, so use the pure-Ruby
|
|
7
|
+
# win32ole-ffi gem there instead.
|
|
8
|
+
if Gem.win_platform?
|
|
9
|
+
if RUBY_ENGINE == 'jruby'
|
|
10
|
+
gem 'win32ole-ffi', '>= 0.1.0'
|
|
11
|
+
else
|
|
12
|
+
gem 'win32ole', '>= 1.8.8'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
7
15
|
|
|
8
16
|
gem 'cap2', '>= 0.2.2' if RUBY_PLATFORM =~ /linux/i
|
|
17
|
+
|
|
18
|
+
# byebug's C extension does not build on JRuby.
|
|
19
|
+
gem 'pry-byebug', '>= 0' unless RUBY_ENGINE == 'jruby'
|
|
20
|
+
|
|
21
|
+
# Validates sig/**/*.rbs. Requires Ruby >= 3.2.
|
|
22
|
+
gem 'rbs', '>= 3', require: false if RUBY_VERSION >= '3.2'
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
net-ping (
|
|
4
|
+
net-ping (3.0.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -17,8 +17,10 @@ GEM
|
|
|
17
17
|
rexml
|
|
18
18
|
hashdiff (1.2.1)
|
|
19
19
|
io-console (0.8.2)
|
|
20
|
+
logger (1.7.0)
|
|
20
21
|
method_source (1.1.0)
|
|
21
22
|
power_assert (3.0.1)
|
|
23
|
+
prism (1.9.0)
|
|
22
24
|
pry (0.16.0)
|
|
23
25
|
coderay (~> 1.1)
|
|
24
26
|
method_source (~> 1.0)
|
|
@@ -28,11 +30,16 @@ GEM
|
|
|
28
30
|
pry (>= 0.13, < 0.17)
|
|
29
31
|
public_suffix (7.0.5)
|
|
30
32
|
rake (13.4.2)
|
|
33
|
+
rbs (4.2.0)
|
|
34
|
+
logger
|
|
35
|
+
prism (>= 1.6.0)
|
|
36
|
+
tsort
|
|
31
37
|
reline (0.6.3)
|
|
32
38
|
io-console (~> 0.5)
|
|
33
39
|
rexml (3.4.4)
|
|
34
40
|
test-unit (3.7.8)
|
|
35
41
|
power_assert
|
|
42
|
+
tsort (0.2.0)
|
|
36
43
|
webmock (3.26.2)
|
|
37
44
|
addressable (>= 2.8.0)
|
|
38
45
|
crack (>= 0.3.2)
|
|
@@ -46,6 +53,7 @@ DEPENDENCIES
|
|
|
46
53
|
net-ping!
|
|
47
54
|
pry-byebug
|
|
48
55
|
rake
|
|
56
|
+
rbs (>= 3)
|
|
49
57
|
test-unit
|
|
50
58
|
webmock
|
|
51
59
|
|
data/README.md
CHANGED
|
@@ -4,13 +4,14 @@ A collection of classes that provide different ways to ping computers.
|
|
|
4
4
|
## Prerequisites
|
|
5
5
|
* ffi
|
|
6
6
|
* win32-security (installed from the Windows gem artifact)
|
|
7
|
-
* win32ole (installed from the Windows gem artifact)
|
|
7
|
+
* win32ole (installed from the Windows gem artifact), or win32ole-ffi on JRuby
|
|
8
8
|
* cap2 (installed from the Linux gem artifact)
|
|
9
9
|
* webmock (test only)
|
|
10
10
|
* test-unit (test only)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
CI covers the following versions:
|
|
13
|
+
* Ruby: 4.0, 3.4, 3.3, 3.2, 3.1, 3.0, 2.7
|
|
14
|
+
* JRuby: 10.1, 10.0
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
```gem install net-ping```
|
|
@@ -47,6 +48,14 @@ A collection of classes that provide different ways to ping computers.
|
|
|
47
48
|
ICMP pings will not work with JRuby without some sort of third-party
|
|
48
49
|
library support for raw sockets in Java, such as RockSaw.
|
|
49
50
|
|
|
51
|
+
WMI pings will not work on JRuby unless you separately `gem install
|
|
52
|
+
win32ole-ffi`. Without it, `require 'net/ping'` prints a warning and
|
|
53
|
+
leaves `Net::Ping::WMI` undefined, rather than raising. The published
|
|
54
|
+
net-ping gem can't declare this automatically: RubyGems' JRuby platform
|
|
55
|
+
tag doesn't distinguish Windows from other OSes, so there's no
|
|
56
|
+
platform-specific gemspec to attach a
|
|
57
|
+
Windows-only dependency to.
|
|
58
|
+
|
|
50
59
|
## License
|
|
51
60
|
Artistic 2.0
|
|
52
61
|
|
data/Rakefile
CHANGED
|
@@ -180,4 +180,11 @@ namespace 'test' do
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
+
namespace 'sig' do
|
|
184
|
+
desc 'Validate the RBS type signatures under sig/'
|
|
185
|
+
task :validate do
|
|
186
|
+
sh 'bundle exec rbs -I sig -r socket -r timeout -r open3 -r uri -r net-http -r openssl validate'
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
183
190
|
task :default => :test
|
data/lib/net/ping/icmp.rb
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'ping')
|
|
2
2
|
|
|
3
3
|
if File::ALT_SEPARATOR
|
|
4
|
-
|
|
4
|
+
begin
|
|
5
|
+
require 'win32/security'
|
|
6
|
+
rescue LoadError => err
|
|
7
|
+
warn "Elevated-privilege detection is unavailable (#{err.message}). Run `gem install win32-security` to enable it."
|
|
8
|
+
end
|
|
5
9
|
end
|
|
6
10
|
|
|
7
11
|
# The Net module serves as a namespace only.
|
|
@@ -45,6 +49,10 @@ module Net
|
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
if File::ALT_SEPARATOR
|
|
52
|
+
unless defined?(Win32::Security)
|
|
53
|
+
raise LoadError, 'win32-security is required for elevated-privilege detection on Windows; run `gem install win32-security`'
|
|
54
|
+
end
|
|
55
|
+
|
|
48
56
|
unless Win32::Security.elevated_security?
|
|
49
57
|
raise 'requires elevated security'
|
|
50
58
|
end
|
data/lib/net/ping/tcp.rb
CHANGED
|
@@ -67,31 +67,47 @@ module Net
|
|
|
67
67
|
return false
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if resp.nil? # Assume ECONNREFUSED if nil
|
|
73
|
-
if @@service_check
|
|
74
|
-
bool = true
|
|
75
|
-
else
|
|
76
|
-
bool = false
|
|
77
|
-
@exception = Errno::ECONNREFUSED
|
|
78
|
-
end
|
|
79
|
-
else
|
|
80
|
-
sockopt = sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR)
|
|
70
|
+
begin
|
|
71
|
+
resp = IO.select(nil, [sock], nil, timeout)
|
|
81
72
|
|
|
82
|
-
if
|
|
83
|
-
if @@service_check
|
|
73
|
+
if resp.nil? # Assume ECONNREFUSED if nil
|
|
74
|
+
if @@service_check
|
|
84
75
|
bool = true
|
|
85
76
|
else
|
|
86
77
|
bool = false
|
|
87
|
-
@exception =
|
|
78
|
+
@exception = Errno::ECONNREFUSED
|
|
88
79
|
end
|
|
89
80
|
else
|
|
81
|
+
sockopt = sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR)
|
|
82
|
+
|
|
83
|
+
if sockopt.int != 0
|
|
84
|
+
if @@service_check && sockopt.int == Errno::ECONNREFUSED::Errno
|
|
85
|
+
bool = true
|
|
86
|
+
else
|
|
87
|
+
bool = false
|
|
88
|
+
@exception = SystemCallError.new(sockopt.int)
|
|
89
|
+
end
|
|
90
|
+
else
|
|
91
|
+
bool = true
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
rescue SystemCallError, IOError => err
|
|
95
|
+
# JRuby raises directly out of IO.select when the connection
|
|
96
|
+
# is refused, instead of surfacing it via SO_ERROR like MRI does.
|
|
97
|
+
if @@service_check && err.is_a?(Errno::ECONNREFUSED)
|
|
90
98
|
bool = true
|
|
99
|
+
else
|
|
100
|
+
bool = false
|
|
101
|
+
@exception = err
|
|
91
102
|
end
|
|
92
103
|
end
|
|
93
104
|
ensure
|
|
94
|
-
|
|
105
|
+
# JRuby invalidates the socket's file descriptor as a side effect
|
|
106
|
+
# of the IO.select error above, so a subsequent close raises EBADF.
|
|
107
|
+
begin
|
|
108
|
+
sock.close if sock
|
|
109
|
+
rescue Errno::EBADF, IOError
|
|
110
|
+
end
|
|
95
111
|
end
|
|
96
112
|
|
|
97
113
|
# There is no duration if the ping failed
|
data/lib/net/ping/udp.rb
CHANGED
|
@@ -85,12 +85,33 @@ module Net
|
|
|
85
85
|
|
|
86
86
|
start_time = Time.now
|
|
87
87
|
|
|
88
|
+
# Process.clock_gettime(Process::CLOCK_MONOTONIC), rather than
|
|
89
|
+
# Time.now, so a wall-clock adjustment mid-ping can't shorten or
|
|
90
|
+
# extend the deadline. Matches Timeout.timeout's own treatment of
|
|
91
|
+
# nil/0 as "no timeout".
|
|
92
|
+
if @timeout && !@timeout.zero?
|
|
93
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
|
|
94
|
+
end
|
|
95
|
+
|
|
88
96
|
begin
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
udp.connect(host, @port)
|
|
98
|
+
udp.send(@data, 0)
|
|
99
|
+
|
|
100
|
+
# Timeout.timeout relies on interrupting the blocking recvfrom
|
|
101
|
+
# call, which JRuby does not honor. Wait for readability with
|
|
102
|
+
# select instead, which enforces the timeout at the OS level.
|
|
103
|
+
# The remaining time (rather than the full @timeout) is used so
|
|
104
|
+
# that time already spent on connect/send still counts against
|
|
105
|
+
# the deadline.
|
|
106
|
+
if deadline
|
|
107
|
+
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
108
|
+
raise Timeout::Error if remaining <= 0
|
|
109
|
+
raise Timeout::Error unless select([udp], nil, nil, remaining)
|
|
110
|
+
else
|
|
111
|
+
select([udp])
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
array = udp.recvfrom(MAX_DATA)
|
|
94
115
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET => err
|
|
95
116
|
if @@service_check
|
|
96
117
|
@exception = err
|
data/lib/net/ping/version.rb
CHANGED
data/lib/net/ping/wmi.rb
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'ping')
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
# win32ole's C extension does not build on JRuby, so use the pure-Ruby
|
|
4
|
+
# win32ole-ffi gem there instead.
|
|
5
|
+
if RUBY_ENGINE == 'jruby'
|
|
6
|
+
require 'win32ole/ffi'
|
|
7
|
+
else
|
|
8
|
+
require 'win32ole'
|
|
9
|
+
end
|
|
3
10
|
|
|
4
11
|
# The Net module serves as a namespace only.
|
|
5
12
|
#
|
data/lib/net/ping.rb
CHANGED
|
@@ -20,5 +20,10 @@ rescue Errno::ENOENT
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
if File::ALT_SEPARATOR
|
|
23
|
-
|
|
23
|
+
begin
|
|
24
|
+
require_relative 'ping/wmi'
|
|
25
|
+
rescue LoadError => err
|
|
26
|
+
gem_name = RUBY_ENGINE == 'jruby' ? 'win32ole-ffi' : 'win32ole'
|
|
27
|
+
warn "Net::Ping::WMI is unavailable (#{err.message}). Run `gem install #{gem_name}` to enable it."
|
|
28
|
+
end
|
|
24
29
|
end
|
data/net-ping.gemspec
CHANGED
|
@@ -22,13 +22,12 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
|
|
23
23
|
spec.extra_rdoc_files = ['README.md', 'CHANGES', 'doc/ping.txt']
|
|
24
24
|
|
|
25
|
-
#
|
|
26
|
-
spec.required_ruby_version = ">=
|
|
25
|
+
# Matches the lowest Ruby version covered by CI.
|
|
26
|
+
spec.required_ruby_version = ">= 2.7"
|
|
27
27
|
|
|
28
28
|
spec.add_development_dependency('test-unit', '>= 0')
|
|
29
29
|
spec.add_development_dependency('webmock', '>= 0')
|
|
30
30
|
spec.add_development_dependency('rake', '>= 0')
|
|
31
|
-
spec.add_development_dependency('pry-byebug', '>= 0')
|
|
32
31
|
|
|
33
32
|
spec.description = <<-EOF
|
|
34
33
|
The net-ping library provides a ping interface for Ruby. It includes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
class External < Ping
|
|
4
|
+
def ping: (?String? host, ?Integer count, ?Numeric interval, ?Numeric timeout) -> bool
|
|
5
|
+
|
|
6
|
+
def ping6: (?String? host, ?Integer count, ?Numeric interval, ?Numeric timeout) -> bool
|
|
7
|
+
|
|
8
|
+
alias ping? ping
|
|
9
|
+
|
|
10
|
+
alias pingecho ping
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
class HTTP < Ping
|
|
4
|
+
attr_accessor follow_redirect: bool
|
|
5
|
+
|
|
6
|
+
attr_accessor redirect_limit: Integer
|
|
7
|
+
|
|
8
|
+
attr_accessor user_agent: String?
|
|
9
|
+
|
|
10
|
+
attr_accessor ssl_verify_mode: Integer
|
|
11
|
+
|
|
12
|
+
attr_accessor get_request: bool
|
|
13
|
+
|
|
14
|
+
attr_accessor proxied: bool?
|
|
15
|
+
|
|
16
|
+
attr_reader code: String?
|
|
17
|
+
|
|
18
|
+
# Narrower than the inherited `(Integer | String)?`: `ping` calls `port.to_i`
|
|
19
|
+
# on this value (lib/net/ping/http.rb:89-90), so a service-name string such as
|
|
20
|
+
# "https" silently becomes port 0 instead of being resolved, unlike TCP/UDP/ICMP
|
|
21
|
+
# which pass the port through to socket APIs that resolve service names.
|
|
22
|
+
attr_accessor port: Integer?
|
|
23
|
+
|
|
24
|
+
def initialize: (?String? uri, ?Integer? port, ?Numeric? timeout) ?{ (self) -> void } -> void
|
|
25
|
+
|
|
26
|
+
def ping: (?String? host) -> bool
|
|
27
|
+
|
|
28
|
+
alias follow_redirect? follow_redirect
|
|
29
|
+
|
|
30
|
+
alias uri host
|
|
31
|
+
|
|
32
|
+
alias uri= host=
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def redirect?: (Net::HTTPResponse? response) -> bool?
|
|
37
|
+
|
|
38
|
+
def do_ping: (URI::Generic uri, Integer? port) -> Net::HTTPResponse?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
class ICMP < Ping
|
|
4
|
+
ICMP_ECHOREPLY: Integer
|
|
5
|
+
|
|
6
|
+
ICMP_ECHO: Integer
|
|
7
|
+
|
|
8
|
+
ICMP_SUBCODE: Integer
|
|
9
|
+
|
|
10
|
+
attr_reader data_size: Integer
|
|
11
|
+
|
|
12
|
+
def data_size=: (Integer size) -> Integer
|
|
13
|
+
|
|
14
|
+
def bind: (String host, ?Integer port) -> Integer
|
|
15
|
+
|
|
16
|
+
def ping: (?String? host) -> (Float | false | nil)
|
|
17
|
+
|
|
18
|
+
# Always raises NoMethodError: `undef_method :port=` in lib/net/ping/icmp.rb
|
|
19
|
+
# removes the writer inherited from Ping. RBS has no syntax to un-declare an
|
|
20
|
+
# inherited method, so this override documents the call as unreachable.
|
|
21
|
+
def port=: ((Integer | String)?) -> bot
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def checksum: (String msg) -> Integer
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
attr_accessor host: String?
|
|
4
|
+
|
|
5
|
+
attr_accessor port: (Integer | String)?
|
|
6
|
+
|
|
7
|
+
attr_accessor timeout: Numeric?
|
|
8
|
+
|
|
9
|
+
attr_reader exception: (Exception | String | singleton(Errno::ECONNREFUSED))?
|
|
10
|
+
|
|
11
|
+
attr_reader warning: String?
|
|
12
|
+
|
|
13
|
+
attr_reader duration: Float?
|
|
14
|
+
|
|
15
|
+
def initialize: (?String? host, ?(Integer | String)? port, ?Numeric? timeout) ?{ (self) -> void } -> void
|
|
16
|
+
|
|
17
|
+
def ping: (?String? host) -> void
|
|
18
|
+
|
|
19
|
+
def ping6: (?String? host) -> void
|
|
20
|
+
|
|
21
|
+
def ping?: (?String? host) -> bool
|
|
22
|
+
|
|
23
|
+
alias pingecho ping
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
class TCP < Ping
|
|
4
|
+
def self.service_check: () -> bool
|
|
5
|
+
|
|
6
|
+
def self.service_check=: (bool) -> bool
|
|
7
|
+
|
|
8
|
+
def ping: (?String? host) -> (Float | false | nil)
|
|
9
|
+
|
|
10
|
+
def self.econnrefused: () -> bool
|
|
11
|
+
|
|
12
|
+
def self.econnrefused=: (bool) -> bool
|
|
13
|
+
|
|
14
|
+
def self.ecr: () -> bool
|
|
15
|
+
|
|
16
|
+
def self.ecr=: (bool) -> bool
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Net
|
|
2
|
+
class Ping
|
|
3
|
+
class UDP < Ping
|
|
4
|
+
MAX_DATA: Integer
|
|
5
|
+
|
|
6
|
+
attr_reader data: String
|
|
7
|
+
|
|
8
|
+
def self.service_check: () -> bool
|
|
9
|
+
|
|
10
|
+
def self.service_check=: (bool) -> bool
|
|
11
|
+
|
|
12
|
+
def data=: (String string) -> String
|
|
13
|
+
|
|
14
|
+
def bind: (String host, Integer port) -> Integer
|
|
15
|
+
|
|
16
|
+
def ping: (?String? host) -> bool
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class Struct::PingStatus < Struct[untyped]
|
|
2
|
+
attr_accessor address: untyped
|
|
3
|
+
|
|
4
|
+
attr_accessor buffer_size: untyped
|
|
5
|
+
|
|
6
|
+
attr_accessor no_fragmentation: untyped
|
|
7
|
+
|
|
8
|
+
attr_accessor primary_address_resolution_status: untyped
|
|
9
|
+
|
|
10
|
+
attr_accessor protocol_address: untyped
|
|
11
|
+
|
|
12
|
+
attr_accessor protocol_address_resolved: untyped
|
|
13
|
+
|
|
14
|
+
attr_accessor record_route: untyped
|
|
15
|
+
|
|
16
|
+
attr_accessor reply_inconsistency: untyped
|
|
17
|
+
|
|
18
|
+
attr_accessor reply_size: untyped
|
|
19
|
+
|
|
20
|
+
attr_accessor resolve_address_names: untyped
|
|
21
|
+
|
|
22
|
+
attr_accessor response_time: untyped
|
|
23
|
+
|
|
24
|
+
attr_accessor response_time_to_live: untyped
|
|
25
|
+
|
|
26
|
+
attr_accessor route_record: untyped
|
|
27
|
+
|
|
28
|
+
attr_accessor route_record_resolved: untyped
|
|
29
|
+
|
|
30
|
+
attr_accessor source_route: untyped
|
|
31
|
+
|
|
32
|
+
attr_accessor source_route_type: untyped
|
|
33
|
+
|
|
34
|
+
attr_accessor status_code: untyped
|
|
35
|
+
|
|
36
|
+
attr_accessor timeout: untyped
|
|
37
|
+
|
|
38
|
+
attr_accessor timestamp_record: untyped
|
|
39
|
+
|
|
40
|
+
attr_accessor timestamp_record_address: untyped
|
|
41
|
+
|
|
42
|
+
attr_accessor timestamp_record_address_resolved: untyped
|
|
43
|
+
|
|
44
|
+
attr_accessor timestamp_route: untyped
|
|
45
|
+
|
|
46
|
+
attr_accessor time_to_live: untyped
|
|
47
|
+
|
|
48
|
+
attr_accessor type_of_service: untyped
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module Net
|
|
52
|
+
class Ping
|
|
53
|
+
class WMI < Ping
|
|
54
|
+
# `PingStatus = Struct.new('PingStatus', ...)` both creates ::Struct::PingStatus
|
|
55
|
+
# (from the string name) and assigns it to this constant in the enclosing scope.
|
|
56
|
+
PingStatus: singleton(::Struct::PingStatus)
|
|
57
|
+
|
|
58
|
+
def ping: (?String? host, ?Hash[Symbol | String, untyped] options) -> Struct::PingStatus
|
|
59
|
+
|
|
60
|
+
def ping?: (?String? host, ?Hash[Symbol | String, untyped] options) -> bool
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
data/test/test_net_ping.rb
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#######################################################################
|
|
2
|
+
# test_net_ping_lib.rb
|
|
3
|
+
#
|
|
4
|
+
# Test case for the lib/net/ping.rb aggregator require.
|
|
5
|
+
#######################################################################
|
|
6
|
+
require 'open3'
|
|
7
|
+
require 'test-unit'
|
|
8
|
+
|
|
9
|
+
class TestNetPingLib < Test::Unit::TestCase
|
|
10
|
+
ROOT = File.expand_path('..', __dir__)
|
|
11
|
+
|
|
12
|
+
def test_require_tolerates_a_missing_wmi_dependency_on_windows
|
|
13
|
+
omit_if(File::ALT_SEPARATOR, 'win32ole/win32ole-ffi may genuinely be installed here')
|
|
14
|
+
|
|
15
|
+
script = <<~'RUBY'
|
|
16
|
+
File.send(:remove_const, :ALT_SEPARATOR)
|
|
17
|
+
File.const_set(:ALT_SEPARATOR, '\\')
|
|
18
|
+
require 'net/ping'
|
|
19
|
+
puts defined?(Net::Ping::WMI).inspect
|
|
20
|
+
RUBY
|
|
21
|
+
|
|
22
|
+
out, err, status = Open3.capture3(Gem.ruby, '-Ilib', '-e', script, chdir: ROOT)
|
|
23
|
+
|
|
24
|
+
assert_true(status.success?, err)
|
|
25
|
+
assert_equal('nil', out.strip)
|
|
26
|
+
assert_match(/win32ole/, err)
|
|
27
|
+
end
|
|
28
|
+
end
|
data/test/test_net_ping_udp.rb
CHANGED
|
@@ -70,6 +70,33 @@ class TC_Net_Ping_UDP < Test::Unit::TestCase
|
|
|
70
70
|
assert_equal(5, @udp.timeout)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
test "a nil timeout disables the timeout instead of raising" do
|
|
74
|
+
@udp.timeout = nil
|
|
75
|
+
assert_nothing_raised{ @udp.ping? }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
test "a zero timeout disables the timeout instead of failing immediately" do
|
|
79
|
+
@udp.timeout = 0
|
|
80
|
+
assert_true(@udp.ping?)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
test "ping times out when the remote port never replies" do
|
|
84
|
+
silent_peer = UDPSocket.new
|
|
85
|
+
silent_peer.bind('127.0.0.1', 0)
|
|
86
|
+
port = silent_peer.addr[1]
|
|
87
|
+
|
|
88
|
+
udp = Net::Ping::UDP.new('127.0.0.1', port, 1)
|
|
89
|
+
start = Time.now
|
|
90
|
+
assert_false(udp.ping?)
|
|
91
|
+
elapsed = Time.now - start
|
|
92
|
+
|
|
93
|
+
assert_true(elapsed < 2.5, "Actual elapsed: #{elapsed}")
|
|
94
|
+
assert_kind_of(Timeout::Error, udp.exception)
|
|
95
|
+
assert_nil(udp.duration)
|
|
96
|
+
ensure
|
|
97
|
+
silent_peer.close if silent_peer
|
|
98
|
+
end
|
|
99
|
+
|
|
73
100
|
test "exception basic functionality" do
|
|
74
101
|
assert_respond_to(@udp, :exception)
|
|
75
102
|
end
|
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:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Chernesky
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: test-unit
|
|
@@ -52,20 +52,6 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: pry-byebug
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
69
55
|
description: |2
|
|
70
56
|
The net-ping library provides a ping interface for Ruby. It includes
|
|
71
57
|
separate TCP, HTTP, LDAP, ICMP, UDP, WMI (for Windows) and external ping
|
|
@@ -102,11 +88,20 @@ files:
|
|
|
102
88
|
- net-ping-universal-linux.gemspec
|
|
103
89
|
- net-ping-universal-mingw-ucrt.gemspec
|
|
104
90
|
- net-ping.gemspec
|
|
91
|
+
- sig/net/ping/external.rbs
|
|
92
|
+
- sig/net/ping/http.rbs
|
|
93
|
+
- sig/net/ping/icmp.rbs
|
|
94
|
+
- sig/net/ping/ping.rbs
|
|
95
|
+
- sig/net/ping/tcp.rbs
|
|
96
|
+
- sig/net/ping/udp.rbs
|
|
97
|
+
- sig/net/ping/version.rbs
|
|
98
|
+
- sig/net/ping/wmi.rbs
|
|
105
99
|
- test/test_net_ping.rb
|
|
106
100
|
- test/test_net_ping_external.rb
|
|
107
101
|
- test/test_net_ping_gem_packaging.rb
|
|
108
102
|
- test/test_net_ping_http.rb
|
|
109
103
|
- test/test_net_ping_icmp.rb
|
|
104
|
+
- test/test_net_ping_lib.rb
|
|
110
105
|
- test/test_net_ping_tcp.rb
|
|
111
106
|
- test/test_net_ping_udp.rb
|
|
112
107
|
- test/test_net_ping_wmi.rb
|
|
@@ -127,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
127
122
|
requirements:
|
|
128
123
|
- - ">="
|
|
129
124
|
- !ruby/object:Gem::Version
|
|
130
|
-
version:
|
|
125
|
+
version: '2.7'
|
|
131
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
127
|
requirements:
|
|
133
128
|
- - ">="
|