wifiddler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +2 -0
- data/bin/wifiddler +8 -0
- data/lib/wifiddler/version.rb +3 -0
- data/lib/wifiddler.rb +141 -0
- data/spec/integrations/cli_spec.rb +70 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/.keep +0 -0
- data/spec/units/.keep +0 -0
- data/wifiddler.gemspec +28 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06899d81504e3c4827f20c603ff1515b04434bd5
|
4
|
+
data.tar.gz: 629af35d90c7ada00c33cbdd437523855be7b6f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79431411badbce5e64abfd3521f76b63088396a9866666b37c75ab2b3714a7dc63a9927cd4fb3f35416cb1d1bf6a7f26d35e951cbc065379453a96b92acca76d
|
7
|
+
data.tar.gz: 78f2b9ec19ae9de948b0ba0de3542de9aff5641672fad59b126668f63e662d6062bd9061fddfbda1164678ec4c92d7e9acfcd613687d565cac714a8dd6336fbf
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Greg Sterndale
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Wifiddler
|
2
|
+
|
3
|
+
Simple CLI to cycle OSX AirPort (Wi-Fi) off & on until it connects to a network}
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install wifiddler
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ wifiddler
|
12
|
+
|
13
|
+
## TODO
|
14
|
+
|
15
|
+
See [GitHub issues](https://github.com/gsterndale/wifiddler/issues) for a list of desired features and bug fixes.
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it ( https://github.com/[my-github-username]/wifiddler/fork )
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/wifiddler
ADDED
data/lib/wifiddler.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'timeout'
|
3
|
+
require "wifiddler/version"
|
4
|
+
|
5
|
+
module WiFiddler
|
6
|
+
class CLI
|
7
|
+
class TooManyAttempts < StandardError; end
|
8
|
+
|
9
|
+
STEP_DOWN_RATE = 1.5
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def self.run(io, arguments)
|
14
|
+
options = { io: io }
|
15
|
+
options.merge! ArgumentParser.new.parse(arguments)
|
16
|
+
self.new(options).run
|
17
|
+
rescue ArgumentParser::InvalidOption => e
|
18
|
+
io.puts e
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(options = {})
|
23
|
+
self.options = options
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
Timeout::timeout(options[:timeout]) do
|
28
|
+
wait_time = options[:interval]
|
29
|
+
attempts = 0
|
30
|
+
until network
|
31
|
+
raise TooManyAttempts if attempts > options[:attempts]
|
32
|
+
cycle_airport
|
33
|
+
print '.'
|
34
|
+
attempts += 1
|
35
|
+
sleep wait_time
|
36
|
+
wait_time *= STEP_DOWN_RATE
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self.io.puts "\nConnected to '#{network}'"
|
40
|
+
0
|
41
|
+
rescue TooManyAttempts
|
42
|
+
self.io.puts "\nUnable to establish connection after #{options[:attempts]} attempts"
|
43
|
+
1
|
44
|
+
rescue Timeout::Error
|
45
|
+
self.io.puts "\nUnable to establish connection after #{options[:timeout]} seconds"
|
46
|
+
1
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def io
|
52
|
+
self.options[:io]
|
53
|
+
end
|
54
|
+
|
55
|
+
def networksetup(flag)
|
56
|
+
std_read, std_write = IO.pipe
|
57
|
+
err_read, err_write = IO.pipe
|
58
|
+
command = "networksetup -#{flag}"
|
59
|
+
self.io.puts command if options[:verbose]
|
60
|
+
system(command, out: std_write, err: err_write)
|
61
|
+
std_write.close
|
62
|
+
err_write.close
|
63
|
+
std_lines = std_read.readlines
|
64
|
+
err_lines = err_read.readlines
|
65
|
+
self.io.puts std_lines if options[:verbose]
|
66
|
+
return std_lines, err_lines
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# There seem to be three variations of output:
|
71
|
+
# 1.
|
72
|
+
# You are not associated with an AirPort network.
|
73
|
+
#
|
74
|
+
# 2.
|
75
|
+
# You are not associated with an AirPort network.
|
76
|
+
# Wi-Fi power is currently off.
|
77
|
+
#
|
78
|
+
# 3.
|
79
|
+
# Current Wi-Fi Network: Karma Wi-Fi
|
80
|
+
def network
|
81
|
+
lines, errs = networksetup("getairportnetwork #{options[:device_id]}")
|
82
|
+
lines.join('\n') =~ /Current Wi-Fi Network: (.+)$/i
|
83
|
+
$1
|
84
|
+
end
|
85
|
+
|
86
|
+
def cycle_airport
|
87
|
+
%w(off on).each do |state|
|
88
|
+
networksetup("setairportpower - #{state}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class ArgumentParser
|
93
|
+
class InvalidOption < StandardError
|
94
|
+
end
|
95
|
+
|
96
|
+
DEFAULT_OPTIONS = {
|
97
|
+
device_id: "en0",
|
98
|
+
interval: 10,
|
99
|
+
attempts: 100,
|
100
|
+
timeout: 10 * 60,
|
101
|
+
verbose: false
|
102
|
+
}
|
103
|
+
|
104
|
+
def parse(arguments)
|
105
|
+
options = DEFAULT_OPTIONS.dup
|
106
|
+
optparse = OptionParser.new do |opts|
|
107
|
+
opts.banner = <<-BANNER.gsub(/^\s{4}/, '')
|
108
|
+
Cycle airport off & on until there is a connection
|
109
|
+
Usage: wifiddler [options]
|
110
|
+
Example: yourkarma --verbose
|
111
|
+
BANNER
|
112
|
+
|
113
|
+
opts.on('-i', '--interval=INTERVAL', "Seconds to wait after first cycle (default: #{DEFAULT_OPTIONS[:interval]})", Float) do |interval|
|
114
|
+
options[:interval] = interval
|
115
|
+
end
|
116
|
+
opts.on('-t', '--timeout=TIMEOUT', "Seconds to wait before exiting (default: #{DEFAULT_OPTIONS[:timeout]})", Float) do |timeout|
|
117
|
+
options[:timeout] = timeout
|
118
|
+
end
|
119
|
+
opts.on('-a', '--attempts=attempts', "Number of cycle attempts (default: #{DEFAULT_OPTIONS[:attempts]})", Integer) do |attempts|
|
120
|
+
options[:attempts] = attempts
|
121
|
+
end
|
122
|
+
opts.on('-d', '--device=DEVICE_ID', "Airport device ID (default: #{DEFAULT_OPTIONS[:device_id]})", String) do |device_id|
|
123
|
+
options[:device_id] = device_id
|
124
|
+
end
|
125
|
+
opts.on('-v', '--[no-]verbose', "Run verbosely (default: #{DEFAULT_OPTIONS[:verbose]})") do |v|
|
126
|
+
options[:verbose] = true
|
127
|
+
end
|
128
|
+
opts.on('-h', '--help', 'Display this screen') do
|
129
|
+
raise InvalidOption, opts
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
optparse.parse!(arguments)
|
134
|
+
|
135
|
+
options
|
136
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
137
|
+
raise InvalidOption, optparse
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CLI" do
|
4
|
+
let(:io) { StringIO.new }
|
5
|
+
let(:args) { ['--interval', '0.00001', '--timeout', '0.001', '--verbose'] }
|
6
|
+
let(:cli) { WiFiddler::CLI.run(io, args) }
|
7
|
+
|
8
|
+
def stub_any_command_output(output)
|
9
|
+
WiFiddler::CLI.any_instance.stub(:system) do |command, options|
|
10
|
+
options[:out].write output
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "output" do
|
15
|
+
subject do
|
16
|
+
cli
|
17
|
+
io.string
|
18
|
+
end
|
19
|
+
|
20
|
+
context "connected to a network" do
|
21
|
+
before do
|
22
|
+
stub_any_command_output "Current Wi-Fi Network: Karma Wi-Fi"
|
23
|
+
end
|
24
|
+
|
25
|
+
it { should match /connected/i }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "not connected to a network" do
|
29
|
+
before do
|
30
|
+
stub_any_command_output "You are not associated with an AirPort network."
|
31
|
+
end
|
32
|
+
it { should match /unable to establish connection/i }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "taking too long" do
|
36
|
+
let(:args) { ['--interval', '10', '--timeout', '0.0001', '--verbose'] }
|
37
|
+
before do
|
38
|
+
stub_any_command_output "You are not associated with an AirPort network."
|
39
|
+
end
|
40
|
+
it { should match /unable to establish connection after 0.0001 seconds/i }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "taking too many attempts" do
|
44
|
+
let(:args) { ['--interval', '0.0001', '--timeout', '2', '--attempts', '2', '--verbose'] }
|
45
|
+
before do
|
46
|
+
stub_any_command_output "You are not associated with an AirPort network."
|
47
|
+
end
|
48
|
+
it { should match /unable to establish connection after 2 attempts/i }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "status code" do
|
53
|
+
subject { cli }
|
54
|
+
|
55
|
+
context "connected to a network" do
|
56
|
+
before do
|
57
|
+
stub_any_command_output "Current Wi-Fi Network: Karma Wi-Fi"
|
58
|
+
end
|
59
|
+
|
60
|
+
it { should be 0 }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "not connected to a network" do
|
64
|
+
before do
|
65
|
+
stub_any_command_output "You are not associated with an AirPort network."
|
66
|
+
end
|
67
|
+
it { should be 1 }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "../lib/wifiddler.rb")
|
9
|
+
|
10
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)), "support/**/*.rb")].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
data/spec/support/.keep
ADDED
File without changes
|
data/spec/units/.keep
ADDED
File without changes
|
data/wifiddler.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wifiddler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wifiddler"
|
8
|
+
spec.version = Wifiddler::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Greg Sterndale"]
|
11
|
+
spec.email = ["gsterndale@gmail.com"]
|
12
|
+
spec.summary = %q{Simple CLI to cycle OSX AirPort (Wi-Fi) off & on}
|
13
|
+
spec.description = %q{Cycle your AirPort off & on until it connects to a network}
|
14
|
+
spec.homepage = "http://github.com/gsterndale/wifiddler"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec", "~> 2.1"
|
25
|
+
|
26
|
+
# Release every merge to master as a prerelease
|
27
|
+
spec.version = "#{spec.version}.pre#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wifiddler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg Sterndale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
description: Cycle your AirPort off & on until it connects to a network
|
56
|
+
email:
|
57
|
+
- gsterndale@gmail.com
|
58
|
+
executables:
|
59
|
+
- wifiddler
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/wifiddler
|
70
|
+
- lib/wifiddler.rb
|
71
|
+
- lib/wifiddler/version.rb
|
72
|
+
- spec/integrations/cli_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/support/.keep
|
75
|
+
- spec/units/.keep
|
76
|
+
- wifiddler.gemspec
|
77
|
+
homepage: http://github.com/gsterndale/wifiddler
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Simple CLI to cycle OSX AirPort (Wi-Fi) off & on
|
101
|
+
test_files:
|
102
|
+
- spec/integrations/cli_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/support/.keep
|
105
|
+
- spec/units/.keep
|