network_tester 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87dd6b11f63f3abcefce9efdea334272f816075104cd2e4066ce0db2734f031e
4
- data.tar.gz: 4733da0cea9b8d0f9bbff93b59b0e947749c183728604c77a35adccd2331a4e6
3
+ metadata.gz: c34cef054f5d83352dc9ba90dede6ff13a591111718cce5690058c967b0eede7
4
+ data.tar.gz: 68ce2bb1b2b083d57362b221f1490ea9a73c7f315694232a3e5151910ab73f70
5
5
  SHA512:
6
- metadata.gz: faffae1e9f29c2d1e27120d33f255a2f5c55f75e64bb9c1acc7edb8569b4079bd5b0640c43fb3cf744aba628d477c6ef5fa3cad22d563ab0b51ea185be7e0e25
7
- data.tar.gz: 0b71fc503dc497bbb2ce1b5dbfd2c757cadf751ac69adedf886bd1490c5ee805de63b49d0b423583c7e89336b9983724227c01a71f25add00f35180e00a12312
6
+ metadata.gz: 442168411af60214c6e4250add31def93869268cc1c313bc8d5c2244223ffa386e087b0c891852388a118d3cb37054fec561ceadabaca7b0a2c598f1be01443b
7
+ data.tar.gz: 574afd62cc5a9b3914a2b3b651be6a1e607d46ce2d915f6b0bf3cd87cda2b3c810a91556917f3e4ca22ca4f5a65325395c2c0840a4fa97d39b63b470b815e782
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .claude
11
+ network_tester-*
data/README.md CHANGED
@@ -1,21 +1,15 @@
1
1
  # NetworkTester
2
2
 
3
- Announces the number of milliseconds it takes for a ping response. Can pass the millisecond threshold before announcement.
3
+ Announces the number of milliseconds it takes for a ping response. When the ping exceeds a configurable threshold, it alerts you audibly (speech on Mac, terminal bell on Linux).
4
4
 
5
5
  When diagnosing network issues, you may want to plug and unplug ethernet cables to search for a problem. The genesis of this project is I wanted a way to do this without carrying my laptop around and looking at it all the time.
6
6
 
7
- On a Mac, the number of milliseconds taken by the ping is announced. On Linux, I believe there is an audible beep when the ping takes longer than the threshold. (Untested.)
7
+ On a Mac, the number of milliseconds taken by the ping is spoken aloud. On Linux, a terminal bell and text warning are printed when the ping exceeds the threshold.
8
8
 
9
9
  ## Installation
10
10
 
11
- Install it to get the bin file:
12
-
13
11
  $ gem install network_tester
14
12
 
15
- OR, if you don't have rvm/rbenv installed, you may need to get it this way:
16
-
17
- $ sudo gem install network_tester
18
-
19
13
  Or add this line to your application's Gemfile:
20
14
 
21
15
  ```ruby
@@ -30,7 +24,27 @@ And then execute:
30
24
 
31
25
  After installing the gem, you may need to open a new shell, and then type:
32
26
 
33
- network_tester [millisecond_threshold=70] [ipaddr=google.com]
27
+ network_tester [options]
28
+ network_tester [maxtime] [address]
29
+
30
+ Positional arguments can be given in any order. Integers are treated as
31
+ the alert threshold; anything else as the host.
32
+
33
+ ### Options
34
+
35
+ -a, --address ADDRESS Host to ping (default: google.com)
36
+ -m, --maxtime MS Alert threshold in ms (default: 70)
37
+ -h, --help Show help message
38
+ -v, --version Show version
39
+
40
+ ### Examples
41
+
42
+ network_tester # ping google.com, alert above 70ms
43
+ network_tester 100 # ping google.com, alert above 100ms
44
+ network_tester yahoo.com # ping yahoo.com, alert above 70ms
45
+ network_tester 100 yahoo.com # ping yahoo.com, alert above 100ms
46
+ network_tester yahoo.com 100 # same as above
47
+ network_tester -a 8.8.8.8 -m 100 # using named options
34
48
 
35
49
  ## Development
36
50
 
@@ -40,10 +54,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
40
54
 
41
55
  ## Contributing
42
56
 
43
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/network_tester.
44
-
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/brianmd/network_tester.
45
58
 
46
59
  ## License
47
60
 
48
61
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
-
data/bin/network_tester CHANGED
@@ -1,14 +1,56 @@
1
1
  #!/usr/bin/env ruby
2
- require 'pathname'
2
+ require "optparse"
3
+ require_relative "../lib/network_tester"
3
4
 
4
- $LOAD_PATH.unshift Pathname.new(__FILE__).dirname + '..'
5
+ options = {
6
+ maxtime: 70,
7
+ address: "google.com"
8
+ }
5
9
 
6
- require_relative '../lib/network_tester'
10
+ OptionParser.new do |opts|
11
+ opts.banner = <<~BANNER
12
+ Usage: network_tester [options]
13
+ network_tester [maxtime] [address]
7
14
 
8
- default_maxtime = 70
9
- ipaddr = 'google.com'
15
+ Positional arguments can be given in any order. Integers are
16
+ treated as the alert threshold; anything else as the host.
10
17
 
11
- default_maxtime = Integer(ARGV[0]) if ARGV.size>0
12
- ipaddr = ARGV[1] if ARGV.size>1
18
+ Examples:
19
+ network_tester # ping google.com, alert above 70ms
20
+ network_tester 100 # ping google.com, alert above 100ms
21
+ network_tester yahoo.com # ping yahoo.com, alert above 70ms
22
+ network_tester 100 yahoo.com # ping yahoo.com, alert above 100ms
23
+ network_tester yahoo.com 100 # same as above
13
24
 
14
- NetworkTester::loop(nil, ipaddr, default_maxtime)
25
+ Options:
26
+ BANNER
27
+
28
+ opts.on("-a", "--address ADDRESS", "Host to ping (default: google.com)") do |addr|
29
+ options[:address] = addr
30
+ end
31
+
32
+ opts.on("-m", "--maxtime MS", Integer, "Alert threshold in ms (default: 70)") do |ms|
33
+ options[:maxtime] = ms
34
+ end
35
+
36
+ opts.on("-h", "--help", "Show this help message") do
37
+ puts opts
38
+ exit
39
+ end
40
+
41
+ opts.on("-v", "--version", "Show version") do
42
+ puts NetworkTester::VERSION
43
+ exit
44
+ end
45
+ end.parse!
46
+
47
+ # Positional args in any order: integers are maxtime, anything else is address
48
+ ARGV.each do |arg|
49
+ if arg.match?(/\A\d+\z/)
50
+ options[:maxtime] = Integer(arg)
51
+ else
52
+ options[:address] = arg
53
+ end
54
+ end
55
+
56
+ NetworkTester.loop(nil, options[:address], options[:maxtime])
@@ -1,3 +1,3 @@
1
1
  module NetworkTester
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require "shellwords"
1
2
  require_relative "network_tester/version"
2
3
 
3
4
  module NetworkTester
@@ -21,22 +22,12 @@ module NetworkTester
21
22
 
22
23
  def pingr(addr='google.com')
23
24
  timeout_arg = mac? ? '-t' : '-W'
24
- cmd = "ping -c 1 #{timeout_arg} 1 #{addr} "
25
+ cmd = "ping -c 1 #{timeout_arg} 1 #{Shellwords.shellescape(addr)}"
25
26
  result = `#{cmd} 2>/dev/null`
26
- timerow = nil
27
- result.split("\n").detect do |r|
28
- if r.match(/time/)
29
- timerow = r.match(/cmp_seq.*time=([^ ]*)/)
30
- end
31
- end
32
-
33
- if timerow.nil?
34
- nil
35
- else
36
- timerow[1]
37
- end
27
+ match = result.match(/time=([^\s]+)/)
28
+ match&.[](1)
38
29
  end
39
-
30
+
40
31
  def notifier(time, maxtime=70)
41
32
  if time.nil?
42
33
  return notify('error')
@@ -53,7 +44,7 @@ module NetworkTester
53
44
 
54
45
  def notify(msg='da', rate=600)
55
46
  if mac?
56
- `say #{msg.inspect} -r #{[rate,400].max}`
47
+ system("say", msg.to_s, "-r", [rate, 400].max.to_s)
57
48
  else
58
49
  puts "\a#{' '*20}#{'-'*10} too long: #{msg.inspect}"
59
50
  end
@@ -10,16 +10,17 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["brian@murphydye.com"]
11
11
 
12
12
  spec.summary = %q{Test network with audible pings.}
13
- spec.description = %q{}
14
- spec.homepage = ''
13
+ spec.description = %q{Continuously pings a host and announces response times. Alerts audibly when latency exceeds a threshold.}
14
+ spec.homepage = "https://github.com/brianmd/network_tester"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.required_ruby_version = ">= 2.7"
18
+
17
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
20
  spec.executables = ['network_tester']
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.add_development_dependency "bundler", ">= 2.1"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
23
24
  spec.add_development_dependency "rake", "~> 12.3.3"
24
- spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - bmd
@@ -13,14 +13,14 @@ dependencies:
13
13
  name: bundler
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '2.1'
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ">="
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '2.1'
26
26
  - !ruby/object:Gem::Dependency
@@ -41,17 +41,18 @@ dependencies:
41
41
  name: rspec
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '3.0'
47
47
  type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
54
- description: ''
53
+ version: '3.0'
54
+ description: Continuously pings a host and announces response times. Alerts audibly
55
+ when latency exceeds a threshold.
55
56
  email:
56
57
  - brian@murphydye.com
57
58
  executables:
@@ -71,7 +72,7 @@ files:
71
72
  - lib/network_tester.rb
72
73
  - lib/network_tester/version.rb
73
74
  - network_tester.gemspec
74
- homepage: ''
75
+ homepage: https://github.com/brianmd/network_tester
75
76
  licenses:
76
77
  - MIT
77
78
  metadata: {}
@@ -82,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
83
  requirements:
83
84
  - - ">="
84
85
  - !ruby/object:Gem::Version
85
- version: '0'
86
+ version: '2.7'
86
87
  required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  requirements:
88
89
  - - ">="