airport_mac_changer 1.0.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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Raul Murciano
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+
2
+ # Airport MAC Changer
3
+
4
+ Script to quickly change your Airport's MAC address.
5
+
6
+ Some wifi hotspots give a limited connection time or bandwith for each device by
7
+ looking its MAC address, so with this gem you may get a new MAC address and get connected again.
8
+
9
+ ## Usage:
10
+
11
+ Execute
12
+
13
+ airport_mac_change
14
+
15
+ enter your root password when you're asked for it and wait a bit.
16
+
17
+ If you're currently connected to some network, you'll be automatically desconnected
18
+ to apply the MAC change and automatically reconnected after.
19
+
20
+ ## Supported platforms
21
+ Currently tested only in Snow Leopard, please let me know if it works in a different platform.
22
+
23
+ ## Copyright
24
+
25
+ Copyright (c) 2010 Raul Murciano. See LICENSE for details.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ require 'airport_mac_changer'
5
+ AirportMacChanger.change!
@@ -0,0 +1,97 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module AirportMacChanger
3
+
4
+ class Address
5
+
6
+ attr_accessor :address
7
+
8
+ def size
9
+ 12
10
+ end
11
+
12
+ def initialize(address = nil)
13
+ @address = address || current
14
+ end
15
+
16
+ def current
17
+ current_mac_str = %x{ifconfig en1 | grep ether}.gsub(/[\W]/,'').gsub('ether','')
18
+ current_mac_int = current_mac_str.to_i(16)
19
+ end
20
+
21
+ def to_s
22
+ str = @address.to_s(16)
23
+ left_zeroes = "0" * (12 - str.size)
24
+ str = left_zeroes + str
25
+ str.gsub(/(..)/,"\\1:").gsub(/:\Z/,'')
26
+ end
27
+
28
+ def renew
29
+ @address += 1
30
+ end
31
+
32
+ def set
33
+ command = "sudo ifconfig en1 ether #{self}"
34
+ system command
35
+ sleep(1)
36
+ end
37
+
38
+ def self.reset
39
+ address = new
40
+ puts "Current MAC address: \t#{address}"
41
+ address.renew
42
+ puts "New MAC address: \t#{address}"
43
+ address.set
44
+ puts "Current MAC address: \t#{new}"
45
+ end
46
+
47
+ end
48
+
49
+ class Connection
50
+
51
+ def self.disconnected
52
+ network = current_network
53
+ if network
54
+ disconnect
55
+ yield
56
+ connect network
57
+ else
58
+ yield
59
+ end
60
+ end
61
+
62
+ def self.current_network
63
+ network = %x{/usr/sbin/networksetup -getairportnetwork Airport}.gsub('Current AirPort Network: ', '').gsub("\n",'')
64
+ (network != 'You are not associated with an AirPort network.') && network
65
+ end
66
+
67
+ def self.disconnect
68
+ print "Disconnecting Airport... "
69
+ system "sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z"
70
+ sleep(10)
71
+ if network = current_network
72
+ puts "still connected to #{network}"
73
+ else
74
+ puts "OK"
75
+ end
76
+ end
77
+
78
+ def self.connect(network)
79
+ print "Connecting Airport to '#{network}'... "
80
+ system "/usr/sbin/networksetup -setairportnetwork Airport #{network}"
81
+ network = current_network
82
+ if network
83
+ puts "OK"
84
+ else
85
+ puts "Whoops, Airport not connected"
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ def self.change!
92
+ Connection.disconnected do
93
+ Address.reset
94
+ end
95
+ end
96
+
97
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airport_mac_changer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Raul Murciano
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-08 00:00:00 +02:00
19
+ default_executable: airport_mac_changer
20
+ dependencies: []
21
+
22
+ description: Script to change your Airport's MAC address
23
+ email: raul@murciano.net
24
+ executables:
25
+ - airport_mac_changer
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.md
31
+ files:
32
+ - lib/airport_mac_changer.rb
33
+ - LICENSE
34
+ - README.md
35
+ - bin/airport_mac_changer
36
+ has_rdoc: true
37
+ homepage: http://github.com/raul/airport_mac_changer
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Quickly change your Airport's MAC address
70
+ test_files: []
71
+