wifi-wand 2.18.0 → 2.19.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/RELEASE_NOTES.md +5 -0
- data/lib/wifi-wand/models/base_model.rb +18 -19
- data/lib/wifi-wand/models/mac_os_model.rb +21 -10
- data/lib/wifi-wand/version.rb +1 -1
- data/swift/WifiNetworkConnecter.swift +57 -0
- data/swift/WifiNetworkDisconecter.swift +1 -1
- data/wifi-wand.gemspec +3 -0
- metadata +18 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3d9a52dffd83c2be845f91172481ee2df4c140d188c3374573f9c76cb43d199
|
|
4
|
+
data.tar.gz: 2962e28498baa51617b5ec42b65304065c1e4aaafd109f2de3e3da1ba8ffde30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23a13c3964972c417dd20131718cb5614ad5a1bfccdd30ee2a52173fd0761ebe40981bd4b11e6c8808dfb3aaefc0a0178ccd8fad8d247fd6413776676af5bf3e
|
|
7
|
+
data.tar.gz: 603dbd8e5eb821df3b42112eac3c5ba92b92e953a2913a56b813190491a69b8a4a91172a2963b05f350bf65340bd007332f63e0e94601130862316970cfafeef
|
data/RELEASE_NOTES.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## v2.19.0
|
|
2
|
+
|
|
3
|
+
* Replace `networksetup` with Swift script for connecting to a network.
|
|
4
|
+
* For getting connected network name, replace `networksetup` with `ipconfig`.
|
|
5
|
+
|
|
1
6
|
## v2.18.0
|
|
2
7
|
|
|
3
8
|
* Remove 'hotspot_login_required' informational item and logic (was not working correctly).
|
|
@@ -11,25 +11,6 @@ class BaseModel
|
|
|
11
11
|
|
|
12
12
|
attr_accessor :wifi_interface, :verbose_mode
|
|
13
13
|
|
|
14
|
-
class OsCommandError < RuntimeError
|
|
15
|
-
attr_reader :exitstatus, :command, :text
|
|
16
|
-
|
|
17
|
-
def initialize(exitstatus, command, text)
|
|
18
|
-
@exitstatus = exitstatus
|
|
19
|
-
@command = command
|
|
20
|
-
@text = text
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def to_s
|
|
24
|
-
"#{self.class.name}: Error code #{exitstatus}, command = #{command}, text = #{text}"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def to_h
|
|
28
|
-
{ exitstatus: exitstatus, command: command, text: text }
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
|
|
33
14
|
def initialize(options)
|
|
34
15
|
@verbose_mode = options.verbose
|
|
35
16
|
|
|
@@ -274,5 +255,23 @@ class BaseModel
|
|
|
274
255
|
def wifi_interface
|
|
275
256
|
@wifi_interface ||= detect_wifi_interface
|
|
276
257
|
end
|
|
258
|
+
|
|
259
|
+
class OsCommandError < RuntimeError
|
|
260
|
+
attr_reader :exitstatus, :command, :text
|
|
261
|
+
|
|
262
|
+
def initialize(exitstatus, command, text)
|
|
263
|
+
@exitstatus = exitstatus
|
|
264
|
+
@command = command
|
|
265
|
+
@text = text
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def to_s
|
|
269
|
+
"#{self.class.name}: Error code #{exitstatus}, command = #{command}, text = #{text}"
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def to_h
|
|
273
|
+
{ exitstatus: exitstatus, command: command, text: text }
|
|
274
|
+
end
|
|
275
|
+
end
|
|
277
276
|
end
|
|
278
277
|
end
|
|
@@ -96,7 +96,7 @@ class MacOsModel < BaseModel
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
# This method is called by BaseModel#connect to do the OS-specific connection logic.
|
|
99
|
-
def
|
|
99
|
+
def os_level_connect_using_networksetup(network_name, password = nil)
|
|
100
100
|
command = "networksetup -setairportnetwork #{wifi_interface} #{Shellwords.shellescape(network_name)}"
|
|
101
101
|
if password
|
|
102
102
|
command << ' ' << Shellwords.shellescape(password)
|
|
@@ -104,6 +104,17 @@ class MacOsModel < BaseModel
|
|
|
104
104
|
run_os_command(command)
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
def os_level_connect_using_swift(network_name, password = nil)
|
|
108
|
+
ensure_swift_and_corewlan_present
|
|
109
|
+
args = [Shellwords.shellescape(network_name)]
|
|
110
|
+
args << Shellwords.shellescape(password) if password
|
|
111
|
+
run_swift_command('WifiNetworkConnecter', *args)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def os_level_connect(network_name, password = nil)
|
|
115
|
+
os_level_connect_using_swift(network_name, password)
|
|
116
|
+
end
|
|
117
|
+
|
|
107
118
|
|
|
108
119
|
# @return:
|
|
109
120
|
# If the network is in the preferred networks list
|
|
@@ -151,10 +162,10 @@ class MacOsModel < BaseModel
|
|
|
151
162
|
def connected_network_name
|
|
152
163
|
return nil unless wifi_on? # no need to try
|
|
153
164
|
|
|
154
|
-
command_output = run_os_command("
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
command_output = run_os_command("ipconfig getsummary #{wifi_interface} | grep ' SSID :'", false)
|
|
166
|
+
return nil if command_output.nil?
|
|
167
|
+
|
|
168
|
+
command_output.split('SSID :').last.strip
|
|
158
169
|
end
|
|
159
170
|
|
|
160
171
|
|
|
@@ -306,12 +317,12 @@ class MacOsModel < BaseModel
|
|
|
306
317
|
system("swift -e 'import CoreWLAN' >/dev/null 2>&1")
|
|
307
318
|
end
|
|
308
319
|
|
|
309
|
-
|
|
320
|
+
|
|
321
|
+
def run_swift_command(basename, *args)
|
|
310
322
|
ensure_swift_and_corewlan_present
|
|
311
|
-
swift_filespec = File.join(
|
|
312
|
-
|
|
313
|
-
)
|
|
314
|
-
command = "swift #{swift_filespec}"
|
|
323
|
+
swift_filespec = File.absolute_path(File.join(File.dirname(__FILE__), "../../../swift/#{basename}.swift"))
|
|
324
|
+
argv = ['swift', swift_filespec] + args
|
|
325
|
+
command = argv.compact.join(' ')
|
|
315
326
|
run_os_command(command)
|
|
316
327
|
end
|
|
317
328
|
end
|
data/lib/wifi-wand/version.rb
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env swift
|
|
2
|
+
|
|
3
|
+
import Foundation
|
|
4
|
+
import CoreWLAN
|
|
5
|
+
|
|
6
|
+
// Function to connect to a network
|
|
7
|
+
func connectToNetwork(ssid: String, password: String?) -> Bool {
|
|
8
|
+
guard let interface = CWWiFiClient.shared().interface() else {
|
|
9
|
+
print("Error: Could not get WiFi interface")
|
|
10
|
+
exit(1)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
do {
|
|
14
|
+
// Scan for networks
|
|
15
|
+
let networks = try interface.scanForNetworks(withSSID: ssid.data(using: .utf8))
|
|
16
|
+
guard let network = networks.first else {
|
|
17
|
+
print("Error: Network not found")
|
|
18
|
+
exit(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Connect to the network
|
|
22
|
+
try interface.associate(to: network, password: password)
|
|
23
|
+
return true
|
|
24
|
+
} catch let error as NSError {
|
|
25
|
+
// Handle specific error cases
|
|
26
|
+
switch error.code {
|
|
27
|
+
case -3931: // Already connected
|
|
28
|
+
print("Already connected to network")
|
|
29
|
+
return true
|
|
30
|
+
case -3906: // Invalid password
|
|
31
|
+
print("Error: Invalid password")
|
|
32
|
+
case -3905: // Network not found
|
|
33
|
+
print("Error: Network not found")
|
|
34
|
+
case -3908: // Timeout
|
|
35
|
+
print("Error: Connection timeout")
|
|
36
|
+
case -3903: // Authentication failed
|
|
37
|
+
print("Error: Authentication failed - might require captive portal login")
|
|
38
|
+
default:
|
|
39
|
+
print("Error connecting: \(error.localizedDescription) (code: \(error.code))")
|
|
40
|
+
}
|
|
41
|
+
exit(1)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Parse command line arguments
|
|
46
|
+
if CommandLine.arguments.count < 2 {
|
|
47
|
+
print("Usage: \(CommandLine.arguments[0]) SSID [password]")
|
|
48
|
+
exit(1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let ssid = CommandLine.arguments[1]
|
|
52
|
+
let password = CommandLine.arguments.count > 2 ? CommandLine.arguments[2] : nil
|
|
53
|
+
|
|
54
|
+
if connectToNetwork(ssid: ssid, password: password) {
|
|
55
|
+
print("ok")
|
|
56
|
+
exit(0)
|
|
57
|
+
}
|
data/wifi-wand.gemspec
CHANGED
|
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
# spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
22
22
|
spec.add_dependency('awesome_print', '>= 1.9.2', '< 2')
|
|
23
23
|
|
|
24
|
+
# ostruct will no longer be part of the default gems starting from Ruby 3.5.0.
|
|
25
|
+
spec.add_dependency('ostruct')
|
|
26
|
+
|
|
24
27
|
# still on version 0, no need to exclude future versions, but need bug fix for pry not pry'ing
|
|
25
28
|
# on last line of method:
|
|
26
29
|
spec.add_dependency('pry', '>= 0.14.2')
|
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.
|
|
4
|
+
version: 2.19.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: 2024-
|
|
11
|
+
date: 2024-12-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: awesome_print
|
|
@@ -30,6 +30,20 @@ dependencies:
|
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '2'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: ostruct
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
33
47
|
- !ruby/object:Gem::Dependency
|
|
34
48
|
name: pry
|
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -135,6 +149,7 @@ files:
|
|
|
135
149
|
- sample-available-networks.yaml
|
|
136
150
|
- spec/wifi-wand/models/base_model_spec.rb
|
|
137
151
|
- swift/AvailableWifiNetworkLister.swift
|
|
152
|
+
- swift/WifiNetworkConnecter.swift
|
|
138
153
|
- swift/WifiNetworkDisconecter.swift
|
|
139
154
|
- test-data/invalid-byte-sequence-network-names.txt
|
|
140
155
|
- wifi-wand.gemspec
|
|
@@ -157,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
172
|
- !ruby/object:Gem::Version
|
|
158
173
|
version: '0'
|
|
159
174
|
requirements: []
|
|
160
|
-
rubygems_version: 3.5.
|
|
175
|
+
rubygems_version: 3.5.23
|
|
161
176
|
signing_key:
|
|
162
177
|
specification_version: 4
|
|
163
178
|
summary: Mac WiFi utility
|