mac-wifi 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/RELEASE_NOTES.md +11 -0
- data/lib/mac-wifi/base_model.rb +21 -1
- data/lib/mac-wifi/command_line_interface.rb +44 -4
- data/lib/mac-wifi/mac_os_model.rb +16 -11
- data/lib/mac-wifi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0049361c430c1be60db595012b1e54844e16ad90df26064c059ba42a9f48fd05'
|
4
|
+
data.tar.gz: 8947e8e004eec02b3a2ca8bf9bc1b24c94a477ccdff7819d8e142e5d7095521a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ac9a874c181bf0b32a4dd59edaaa2d3000a2f0197ba54e43a4425e725a18d115ae63640ed4ba2471cc7277acd70fdd5d61b3c2c0ca4ece4dc1063c3a8aaa46
|
7
|
+
data.tar.gz: cf18aeb2d52e73ddd9acb0444e5196b8c7126a55c6ad11314da9fabce123e5a2da70c26253944de68d10119582256cd266787da25257dc3b7cf33f69a8630428
|
data/README.md
CHANGED
@@ -28,8 +28,7 @@ output at the time of this writing:
|
|
28
28
|
```
|
29
29
|
$ mac-wifi h
|
30
30
|
|
31
|
-
|
32
|
-
Command Line Switches: [mac-wifi version 2.2.0]
|
31
|
+
Command Line Switches: [mac-wifi version 2.3.0]
|
33
32
|
|
34
33
|
-o[i,j,p,y] - outputs data in inspect, JSON, puts, or YAML format when not in shell mode
|
35
34
|
-s - run in shell mode
|
@@ -49,11 +48,11 @@ n[etwork_name] - name (SSID) of currently connected network
|
|
49
48
|
on - turns wifi on
|
50
49
|
of[f] - turns wifi off
|
51
50
|
pa[ssword] network-name - password for preferred network-name
|
52
|
-
pu[blic-ip-show] - opens https://www.whatismyip.com/ in a browser window to show public address info
|
53
51
|
pr[ef_nets] - preferred (not necessarily available) networks
|
54
52
|
q[uit] - exits this program (interactive shell mode only) (see also 'x')
|
55
53
|
r[m_pref_nets] network-name - removes network-name from the preferred networks list
|
56
54
|
(can provide multiple names separated by spaces)
|
55
|
+
ro[pen] - open resource ('ipc' (IP Chicken), 'ipw' (What is My IP), 'spe' (Speed Test), 'this' (mac-wifi Home Page))
|
57
56
|
t[ill] - returns when the desired Internet connection state is true. Options:
|
58
57
|
1) 'on'/:on, 'off'/:off, 'conn'/:conn, or 'disc'/:disc
|
59
58
|
2) wait interval, in seconds (optional, defaults to 0.5 seconds)
|
data/RELEASE_NOTES.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## v2.3.0
|
2
|
+
|
3
|
+
* Add public IP address info to info hash (https://github.com/keithrbennett/macwifi/issues/3).
|
4
|
+
* Add nameserver information to info hash (issue at https://github.com/keithrbennett/macwifi/issues/5).
|
5
|
+
* Made all info hash keys same data type to be less confusing; made them all String's.
|
6
|
+
* Replace 'public-ip-show' with 'ropen', and provide additional targets ipchicken.com,
|
7
|
+
speedtest.net, and the Github page for this project
|
8
|
+
* Speed up retrieval of network name
|
9
|
+
* Remove BaseModel#run_os_command private restriction.
|
10
|
+
|
11
|
+
|
1
12
|
## v2.2.0
|
2
13
|
|
3
14
|
* Add pu[blic-wifi-show] command to open https://www.whatismyip.com/ to show public IP address info.
|
data/lib/mac-wifi/base_model.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'tempfile'
|
2
3
|
require_relative '../mac-wifi'
|
3
4
|
|
@@ -31,7 +32,6 @@ class BaseModel
|
|
31
32
|
end
|
32
33
|
output
|
33
34
|
end
|
34
|
-
private :run_os_command
|
35
35
|
|
36
36
|
|
37
37
|
# This method returns whether or not there is a working Internet connection.
|
@@ -217,5 +217,25 @@ class BaseModel
|
|
217
217
|
end
|
218
218
|
nil
|
219
219
|
end
|
220
|
+
|
221
|
+
|
222
|
+
# Reaches out to ipinfo.io to get public IP address information
|
223
|
+
# in the form of a hash.
|
224
|
+
# You may need to enclose this call in a begin/rescue.
|
225
|
+
def public_ip_address_info
|
226
|
+
JSON.parse(`curl -s ipinfo.io`)
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
# @return array of nameserver IP addresses from /etc/resolv.conf, or nil if not found
|
231
|
+
# Though this is strictly *not* OS-agnostic, it will be used by most OS's,
|
232
|
+
# and can be overridden by subclasses (e.g. Windows).
|
233
|
+
def nameservers
|
234
|
+
begin
|
235
|
+
File.readlines('/etc/resolv.conf').grep(/^nameserver /).map { |line| line.split.last }
|
236
|
+
rescue Errno::ENOENT
|
237
|
+
nil
|
238
|
+
end
|
239
|
+
end
|
220
240
|
end
|
221
241
|
end
|
@@ -4,17 +4,47 @@ module MacWifi
|
|
4
4
|
|
5
5
|
class CommandLineInterface
|
6
6
|
|
7
|
-
attr_reader :model, :
|
7
|
+
attr_reader :interactive_mode, :model, :open_resources, :options
|
8
|
+
|
8
9
|
|
9
10
|
class Command < Struct.new(:min_string, :max_string, :action); end
|
10
11
|
|
11
12
|
|
13
|
+
class OpenResource < Struct.new(:code, :resource, :description)
|
14
|
+
|
15
|
+
# Ex: "'ipw' (What is My IP)"
|
16
|
+
def help_string
|
17
|
+
"'#{code}' (#{description})"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class OpenResources < Array
|
23
|
+
|
24
|
+
def find_by_code(code)
|
25
|
+
detect { |resource| resource.code == code }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Ex: "('ipc' (IP Chicken), 'ipw' (What is My IP), 'spe' (Speed Test))"
|
29
|
+
def help_string
|
30
|
+
map(&:help_string).join(', ')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
12
35
|
class BadCommandError < RuntimeError
|
13
36
|
def initialize(error_message)
|
14
37
|
super
|
15
38
|
end
|
16
39
|
end
|
17
40
|
|
41
|
+
OPEN_RESOURCES = OpenResources.new([
|
42
|
+
OpenResource.new('ipc', 'https://ipchicken.com/', 'IP Chicken'),
|
43
|
+
OpenResource.new('ipw', 'https://www.whatismyip.com', 'What is My IP'),
|
44
|
+
OpenResource.new('spe', 'http://speedtest.net/', 'Speed Test'),
|
45
|
+
OpenResource.new('this', 'https://github.com/keithrbennett/macwifi', 'mac-wifi Home Page'),
|
46
|
+
])
|
47
|
+
|
18
48
|
|
19
49
|
# Help text to be used when requested by 'h' command, in case of unrecognized or nonexistent command, etc.
|
20
50
|
HELP_TEXT = "
|
@@ -38,11 +68,11 @@ n[etwork_name] - name (SSID) of currently connected network
|
|
38
68
|
on - turns wifi on
|
39
69
|
of[f] - turns wifi off
|
40
70
|
pa[ssword] network-name - password for preferred network-name
|
41
|
-
pu[blic-ip-show] - opens https://www.whatismyip.com/ in a browser window to show public address info
|
42
71
|
pr[ef_nets] - preferred (not necessarily available) networks
|
43
72
|
q[uit] - exits this program (interactive shell mode only) (see also 'x')
|
44
73
|
r[m_pref_nets] network-name - removes network-name from the preferred networks list
|
45
74
|
(can provide multiple names separated by spaces)
|
75
|
+
ro[pen] - open resource (#{OPEN_RESOURCES.help_string})
|
46
76
|
t[ill] - returns when the desired Internet connection state is true. Options:
|
47
77
|
1) 'on'/:on, 'off'/:off, 'conn'/:conn, or 'disc'/:disc
|
48
78
|
2) wait interval, in seconds (optional, defaults to 0.5 seconds)
|
@@ -269,7 +299,7 @@ When in interactive shell mode:
|
|
269
299
|
|
270
300
|
|
271
301
|
def cmd_n
|
272
|
-
name = model.
|
302
|
+
name = model.current_network
|
273
303
|
if interactive_mode
|
274
304
|
name
|
275
305
|
else
|
@@ -289,6 +319,16 @@ When in interactive shell mode:
|
|
289
319
|
end
|
290
320
|
|
291
321
|
|
322
|
+
# Use Mac OS 'open' command line utility
|
323
|
+
def cmd_ro(*resource_codes)
|
324
|
+
resource_codes.each do |code|
|
325
|
+
resource = OPEN_RESOURCES.find_by_code(code)
|
326
|
+
if resource
|
327
|
+
model.run_os_command("open #{resource.resource}")
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
292
332
|
def cmd_pa(network)
|
293
333
|
password = model.preferred_network_password(network)
|
294
334
|
|
@@ -371,9 +411,9 @@ When in interactive shell mode:
|
|
371
411
|
Command.new('n', 'network_name', -> (*_options) { cmd_n }),
|
372
412
|
Command.new('of', 'off', -> (*_options) { cmd_of }),
|
373
413
|
Command.new('on', 'on', -> (*_options) { cmd_on }),
|
414
|
+
Command.new('ro', 'ropen', -> (*options) { cmd_ro(*options) }),
|
374
415
|
Command.new('pa', 'password', -> (*options) { cmd_pa(*options) }),
|
375
416
|
Command.new('pr', 'pref_nets', -> (*_options) { cmd_pr }),
|
376
|
-
Command.new('pu', 'public_ip_show',-> (*_options) { cmd_pu }),
|
377
417
|
Command.new('q', 'quit', -> (*_options) { cmd_q }),
|
378
418
|
Command.new('r', 'rm_pref_nets', -> (*options) { cmd_r(*options) }),
|
379
419
|
Command.new('t', 'till', -> (*options) { cmd_t(*options) }),
|
@@ -181,11 +181,6 @@ class MacOsModel < BaseModel
|
|
181
181
|
end
|
182
182
|
|
183
183
|
|
184
|
-
def connected_network_name
|
185
|
-
wifi_info['SSID']
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
184
|
# This method is called by BaseModel#connect to do the OS-specific connection logic.
|
190
185
|
def os_level_connect(network_name, password = nil)
|
191
186
|
command = "networksetup -setairportnetwork #{wifi_hardware_port} " + "#{Shellwords.shellescape(network_name)}"
|
@@ -256,17 +251,27 @@ class MacOsModel < BaseModel
|
|
256
251
|
def wifi_info
|
257
252
|
|
258
253
|
info = {
|
259
|
-
wifi_on
|
260
|
-
internet_on
|
261
|
-
port
|
262
|
-
network
|
263
|
-
ip_address
|
264
|
-
|
254
|
+
'wifi_on' => wifi_on?,
|
255
|
+
'internet_on' => connected_to_internet?,
|
256
|
+
'port' => wifi_hardware_port,
|
257
|
+
'network' => current_network,
|
258
|
+
'ip_address' => ip_address,
|
259
|
+
'nameservers' => nameservers,
|
260
|
+
'timestamp' => Time.now,
|
265
261
|
}
|
266
262
|
more_output = run_os_command(AIRPORT_CMD + " -I")
|
267
263
|
more_info = colon_output_to_hash(more_output)
|
268
264
|
info.merge!(more_info)
|
269
265
|
info.delete('AirPort') # will be here if off, but info is already in wifi_on key
|
266
|
+
|
267
|
+
if info['wifi_on']
|
268
|
+
begin
|
269
|
+
info['public_ip'] = public_ip_address_info
|
270
|
+
rescue => e
|
271
|
+
puts "Error obtaining public IP address info, proceeding with everything else:"
|
272
|
+
puts e.to_s
|
273
|
+
end
|
274
|
+
end
|
270
275
|
info
|
271
276
|
end
|
272
277
|
|
data/lib/mac-wifi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-wifi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.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-01-
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|