dashed 0.1.0 → 0.2.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/README.md +15 -2
- data/exe/find_dash +20 -0
- data/lib/dashed/button.rb +3 -12
- data/lib/dashed/packet.rb +19 -0
- data/lib/dashed/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe157917d1366232d8d4eb8ce2351f1819492a07
|
|
4
|
+
data.tar.gz: cde3f601f4250ea923741956f5432c04a4bf15ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a0ec1697645f7bdf3556c82173dbbf8fc730b04845b651f29a62949e8bfc6864253078b402e203dd862a920114cb11e7cbaf73a9118d6720e68908502ea7cd0
|
|
7
|
+
data.tar.gz: 23d0a912bad2803d10f3107deec64a59d9544bbc60c5cfc922a3e33dbcd2453f8d6cb1f4b0d400b6e823beab83b72d4e921d250c8274a363531a4ad5c09fd0c6
|
data/README.md
CHANGED
|
@@ -4,19 +4,32 @@ Dashed is a Ruby library for interacting with Amazon Dash button presses.
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Just add `dashed` to your
|
|
7
|
+
Just add `dashed` to your Gemfile and then run `bundle install`.
|
|
8
8
|
|
|
9
9
|
Dashed has to be run with root permissions in order to listen to your network
|
|
10
10
|
devices to pick up your dash button.
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
+
Dashed includes the `find_dash` executable which looks for Amazon Dash buttons
|
|
15
|
+
based on their mac address. Once you've found your Dash buttons Mac Address you
|
|
16
|
+
can get started.
|
|
17
|
+
|
|
18
|
+
ex: `sudo find_dash dummylan0` where dummylan0 is the wifi interface to listen
|
|
19
|
+
on. Ensure your Amazon Dash button is connected to the same network.
|
|
20
|
+
|
|
21
|
+
Here is an example implementation:
|
|
22
|
+
|
|
14
23
|
```
|
|
15
|
-
Dashed::Button.new("ff:ff:ff:ff:ff", "dummylan0") do
|
|
24
|
+
Dashed::Button.new("ff:ff:ff:ff:ff", "dummylan0").on_press do
|
|
16
25
|
puts "I was pressed!"
|
|
17
26
|
end
|
|
18
27
|
```
|
|
19
28
|
|
|
29
|
+
Please be aware that `on_press` blocks the execution of the current
|
|
30
|
+
thread. If you don't want it to block please create the button in its own
|
|
31
|
+
thread.
|
|
32
|
+
|
|
20
33
|
## Contributing
|
|
21
34
|
|
|
22
35
|
Bug reports and pull requests are welcome on GitHub at
|
data/exe/find_dash
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'pcaprub'
|
|
4
|
+
require_relative '../lib/dashed/packet'
|
|
5
|
+
|
|
6
|
+
interface = ARGV[0]
|
|
7
|
+
|
|
8
|
+
if interface
|
|
9
|
+
capture = PCAPRUB::Pcap.open_live(interface, 65535, true, 0)
|
|
10
|
+
capture.setfilter("arp")
|
|
11
|
+
|
|
12
|
+
capture.each_packet do |raw_packet|
|
|
13
|
+
packet = Dashed::Packet.new(raw_packet)
|
|
14
|
+
if packet.host_mac_address.start_with? "74:75"
|
|
15
|
+
puts "Potential Amazon Dash Button #{packet.host_mac_address}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
puts "You must provide an interface"
|
|
20
|
+
end
|
data/lib/dashed/button.rb
CHANGED
|
@@ -17,9 +17,9 @@ module Dashed
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def on_press
|
|
20
|
-
capture.each_packet do |
|
|
21
|
-
|
|
22
|
-
if
|
|
20
|
+
capture.each_packet do |raw_packet|
|
|
21
|
+
packet = Packet.new(raw_packet)
|
|
22
|
+
if packet.host_mac_address == mac_address && !duplicate_arp?
|
|
23
23
|
@last_press = Time.now
|
|
24
24
|
yield if block_given?
|
|
25
25
|
end
|
|
@@ -38,14 +38,5 @@ module Dashed
|
|
|
38
38
|
def duplicate_arp?
|
|
39
39
|
last_press && (last_press - Time.now).abs < 45
|
|
40
40
|
end
|
|
41
|
-
|
|
42
|
-
def parse_arp_sender_mac(packet)
|
|
43
|
-
arp = packet.
|
|
44
|
-
data.
|
|
45
|
-
unpack("C*").
|
|
46
|
-
map { |i| i.to_s(16) }.
|
|
47
|
-
map { |i| if i.length == 1 then "0#{i}" else i end}
|
|
48
|
-
arp.slice(6, 6).join(":")
|
|
49
|
-
end
|
|
50
41
|
end
|
|
51
42
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Dashed
|
|
2
|
+
class Packet
|
|
3
|
+
attr_reader :raw_packet
|
|
4
|
+
|
|
5
|
+
def initialize(raw_packet)
|
|
6
|
+
@raw_packet = raw_packet
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def host_mac_address
|
|
10
|
+
raw_packet.
|
|
11
|
+
data.
|
|
12
|
+
unpack("C*").
|
|
13
|
+
map { |i| i.to_s(16) }.
|
|
14
|
+
map { |i| if i.length == 1 then "0#{i}" else i end}.
|
|
15
|
+
slice(6, 6).
|
|
16
|
+
join(":")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/dashed/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dashed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Kenyon
|
|
@@ -57,7 +57,8 @@ description: Library for interacting with Amazon Dash buttons
|
|
|
57
57
|
email:
|
|
58
58
|
- kenyonj@gmail.com
|
|
59
59
|
- blake@blakewilliams.me
|
|
60
|
-
executables:
|
|
60
|
+
executables:
|
|
61
|
+
- find_dash
|
|
61
62
|
extensions: []
|
|
62
63
|
extra_rdoc_files: []
|
|
63
64
|
files:
|
|
@@ -67,8 +68,10 @@ files:
|
|
|
67
68
|
- README.md
|
|
68
69
|
- Rakefile
|
|
69
70
|
- dashed.gemspec
|
|
71
|
+
- exe/find_dash
|
|
70
72
|
- lib/dashed.rb
|
|
71
73
|
- lib/dashed/button.rb
|
|
74
|
+
- lib/dashed/packet.rb
|
|
72
75
|
- lib/dashed/version.rb
|
|
73
76
|
homepage: https://github.com/kenyonj/dashed
|
|
74
77
|
licenses:
|