wifi-wand 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f21e7e9af16e0eea5c7d254ef75ce061fbae1ada6c707201a189ec78f9238be
4
- data.tar.gz: ec4b2ef369ca6e3186fe02b59e57c059f89a17b03eba2cdf760035b93fdaa9b9
3
+ metadata.gz: 3f241f14959069b1206de6183dc072605c5af1c65b1dbfc0f855366194bc3c68
4
+ data.tar.gz: 8bd1250fe4fc050b5810d1c67bd279ce6022974fc9facb236088057966712ec6
5
5
  SHA512:
6
- metadata.gz: a86d2fd563801ca4a3259d200de197d8811c6f46360a805b85779fc488107045c8df20f6013c69866b61bdddcc40f11ff77a338bb2e0984eef8690d86a2016fd
7
- data.tar.gz: cd16ad95aed459d769e51539a911797f004be30e7ad9dfab8c6352d2aaa226cbadcbe46d5d0c4075c58b6f478bb1ccb3f6a66408aa932b1111cf0205d5ea2e3c
6
+ metadata.gz: 3c3e3b3a1da083d30ba3289046d35506c43a6a0a56c443da10e5dc50566ada6e9c5aae829967eb5ac5c0d1a59d49063280397c1a05e5461440945c0415329c5a
7
+ data.tar.gz: d4791602539759a83b8d88f5dd801279559537dc5401fd003bdf2b9cd96083a5ffce957487122ed704e69a13458ef0659b7f7c52b19a74f4a4c9d1ca386d8d42
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v2.12.0
2
+
3
+ * Change connected_to_internet?. Use 'dig' to test name resolution first, then HTTP get. Also, add baidu.com for China where google.com is blocked.
4
+ * Remove ping test from connected_to_internet?. It was failing on a network that had connectivity (Syma in France).
5
+ * Remove trailing newline from MAC address.
6
+ * Fix nameservers command to return empty array instead of ["There aren't any DNS Servers set on Wi-Fi."] (output of underlying command)when no nameservers.
7
+
8
+
1
9
  ## v2.11.0
2
10
 
3
11
  * Various fixes and clarifications.
@@ -66,47 +66,64 @@ class BaseModel
66
66
 
67
67
 
68
68
  # This method returns whether or not there is a working Internet connection,
69
- # which is defined as being able to get a successful response
70
- # from google.com within 3 seconds..
69
+ # which is defined as name resolution and HTTP get being successful.
70
+ # Domains attempted are google.com and baidu.com. Success is either being successful.
71
+ # Commands for the multiple sites are run in parallel, in threads, to save time.
71
72
  def connected_to_internet?
72
73
 
73
- # We test using ping first because that will allow us to fail faster
74
- # if there is no network connection.
75
- test_using_ping = -> do
76
- run_os_command('ping -c 1 -t 3 google.com', false)
77
- $?.exitstatus == 0
78
- end
79
-
74
+ # We cannot use run_os_command for the running of external processes here,
75
+ # because they are multithreaded, and the output will get mixed up.
80
76
 
81
- test_using_http_get = -> do
82
- test_site = 'https://www.google.com'
83
- url = URI.parse(test_site)
84
- success = true
77
+ # First pass to fail quickly if name resolving does not work.
78
+ test_using_dig = -> do
79
+ domains = %w(google.com baidu.com)
80
+ puts "Calling dig on domains #{domains}..." if @verbose_mode
85
81
 
86
- if @verbose_mode
87
- puts CommandOutputFormatter.command_attempt_as_string("[Calling Net:HTTP.start(#{url.host})]")
82
+ threads = domains.map do |domain|
83
+ Thread.new do
84
+ output = `dig +short #{domain}`
85
+ output.length > 0
86
+ end
88
87
  end
89
88
 
90
- start_time = Time.now
89
+ threads.each(&:join)
90
+ values = threads.map(&:value)
91
+ success = values.include?(true)
92
+ puts "Results of dig: success == #{success}, values were #{values}." if @verbose_mode
93
+ success
94
+ end
91
95
 
92
- begin
93
- Net::HTTP.start(url.host) do |http|
94
- http.read_timeout = 3 # seconds
95
- http.get('.')
96
+ test_using_http_get = -> do
97
+ test_sites = %w{https://www.google.com http://baidu.com}
98
+ puts "Calling HTTP.get on sites #{test_sites}..." if @verbose_mode
99
+
100
+ threads = test_sites.map do |site|
101
+ Thread.new do
102
+ url = URI.parse(site)
103
+ success = true
104
+
105
+ begin
106
+ Net::HTTP.start(url.host) do |http|
107
+ http.read_timeout = 3 # seconds
108
+ http.get('.')
109
+ end
110
+ rescue
111
+ success = false
112
+ end
113
+
114
+ success
96
115
  end
97
- rescue
98
- success = false
99
116
  end
100
117
 
101
- if @verbose_mode
102
- puts "Duration: #{'%.4f' % [Time.now - start_time]} seconds"
103
- puts CommandOutputFormatter.command_result_as_string("#{success}\n")
104
- end
118
+ threads.each(&:join)
119
+ values = threads.map(&:value)
120
+ success = values.include?(true)
105
121
 
122
+ puts "Results of HTTP.get: success == #{success}, values were #{values}." if @verbose_mode
106
123
  success
107
124
  end
108
125
 
109
- test_using_ping.() && test_using_http_get.()
126
+ test_using_dig.() && test_using_http_get.()
110
127
  end
111
128
 
112
129
 
@@ -279,7 +279,7 @@ class MacOsModel < BaseModel
279
279
  # then this method returns the current address if none is provided,
280
280
  # but sets to the specified address if it is.
281
281
  def mac_address
282
- run_os_command("ifconfig #{wifi_port} | awk '/ether/{print $2}'")
282
+ run_os_command("ifconfig #{wifi_port} | awk '/ether/{print $2}'").chomp
283
283
  end
284
284
 
285
285
 
@@ -387,6 +387,9 @@ class MacOsModel < BaseModel
387
387
 
388
388
  def nameservers_using_networksetup
389
389
  output = run_os_command("networksetup -getdnsservers Wi-Fi")
390
+ if output == "There aren't any DNS Servers set on Wi-Fi.\n"
391
+ output = ''
392
+ end
390
393
  output.split("\n")
391
394
  end
392
395
  end
@@ -1,5 +1,5 @@
1
1
  module WifiWand
2
2
 
3
- VERSION = '2.11.0'
3
+ VERSION = '2.12.0'
4
4
 
5
5
  end
data/wifi-wand.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["keithrbennett@gmail.com"]
10
10
  spec.description = %q{A command line interface for managing WiFi on a Mac.}
11
11
  spec.summary = %q{Mac WiFi utility}
12
- spec.homepage = "https://github.com/keithrbennett/wifi-wand"
12
+ spec.homepage = "https://github.com/keithrbennett/wifiwand"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wifi-wand
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,7 @@ files:
85
85
  - spec/wifi-wand/models/mac_os_model_spec.rb
86
86
  - test-data/invalid-byte-sequence-network-names.txt
87
87
  - wifi-wand.gemspec
88
- homepage: https://github.com/keithrbennett/wifi-wand
88
+ homepage: https://github.com/keithrbennett/wifiwand
89
89
  licenses:
90
90
  - MIT
91
91
  metadata: {}