presence 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/lib/presence/commands.rb +2 -2
- data/lib/presence/scanner.rb +7 -2
- data/lib/presence/version.rb +1 -1
- data/spec/presence/scanner_spec.rb +15 -5
- metadata +14 -14
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Presence
|
2
2
|
|
3
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/subakva/presence)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/subakva/presence.png)](http://travis-ci.org/subakva/presence)
|
5
|
+
|
3
6
|
Monitors the local network for presence of network clients by MAC address.
|
4
7
|
|
5
8
|
## Installation
|
@@ -18,7 +21,13 @@ Install the gem
|
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
$ presence_scan
|
25
|
+
|
26
|
+
## Reference
|
27
|
+
|
28
|
+
* Source: https://github.com/subakva/presence/
|
29
|
+
* RDoc: http://rdoc.info/github/subakva/presence/master/frames
|
30
|
+
* arping: https://github.com/ThomasHabets/arping
|
22
31
|
|
23
32
|
## Contributing
|
24
33
|
|
data/lib/presence/commands.rb
CHANGED
data/lib/presence/scanner.rb
CHANGED
@@ -5,7 +5,7 @@ module Presence
|
|
5
5
|
# Scans a network for connected clients, captures the MAC address, and
|
6
6
|
# dispatches related events to any registered listeners.
|
7
7
|
class Scanner
|
8
|
-
PAIR = '[0-9a-
|
8
|
+
PAIR = '[0-9a-fA-F]{2}'
|
9
9
|
SEP = '\:'
|
10
10
|
MAC_REGEXP = Regexp.new("(#{6.times.map {PAIR}.join(SEP)})")
|
11
11
|
|
@@ -14,6 +14,7 @@ module Presence
|
|
14
14
|
def initialize(options = nil)
|
15
15
|
options ||= {}
|
16
16
|
self.options = {
|
17
|
+
retries: 1,
|
17
18
|
ip_prefix: nil,
|
18
19
|
octet_range: (1..255)
|
19
20
|
}.merge(options)
|
@@ -45,6 +46,10 @@ module Presence
|
|
45
46
|
options[:octet_range]
|
46
47
|
end
|
47
48
|
|
49
|
+
def retries
|
50
|
+
options[:retries]
|
51
|
+
end
|
52
|
+
|
48
53
|
def scan
|
49
54
|
dispatch(:scan_started, ip_prefix, octet_range)
|
50
55
|
octet_range.each do |i|
|
@@ -54,7 +59,7 @@ module Presence
|
|
54
59
|
end
|
55
60
|
|
56
61
|
def scan_ip(ip)
|
57
|
-
cmd, result = @commands.arping(ip)
|
62
|
+
cmd, result = @commands.arping(ip, retries)
|
58
63
|
dispatch(:ip_scanned, ip, cmd, result)
|
59
64
|
process_scan_result(ip, cmd, result)
|
60
65
|
end
|
data/lib/presence/version.rb
CHANGED
@@ -19,13 +19,14 @@ describe Presence::Scanner do
|
|
19
19
|
listener
|
20
20
|
}
|
21
21
|
let(:octet_range) { (30..32) }
|
22
|
-
let(:
|
22
|
+
let(:retries) { 1 }
|
23
|
+
let(:scanner) { Presence::Scanner.new(octet_range: octet_range, retries: retries) }
|
23
24
|
|
24
25
|
before {
|
25
26
|
commands.stub(:local_ip).and_return(local_ip)
|
26
27
|
commands.stub(:arping).and_return([arping_cmd, 'No such jeaun'])
|
27
|
-
commands.stub(:arping).with(local_ip).and_return([arping_cmd, local_mac])
|
28
|
-
commands.stub(:arping).with(ip).and_return([arping_cmd, mac])
|
28
|
+
commands.stub(:arping).with(local_ip, retries).and_return([arping_cmd, local_mac])
|
29
|
+
commands.stub(:arping).with(ip, retries).and_return([arping_cmd, mac])
|
29
30
|
}
|
30
31
|
|
31
32
|
describe '.check_env' do
|
@@ -105,8 +106,17 @@ describe Presence::Scanner do
|
|
105
106
|
end
|
106
107
|
|
107
108
|
describe '#scan_ip' do
|
109
|
+
context 'with a retries option' do
|
110
|
+
let(:retries) { 4 }
|
111
|
+
|
112
|
+
it 'uses the configured number of retries' do
|
113
|
+
commands.should_receive(:arping).with(ip, 4).and_return([arping_cmd, mac])
|
114
|
+
scanner.scan_ip(ip)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
108
118
|
it 'executes arping to check for a mac address' do
|
109
|
-
commands.should_receive(:arping).with(ip).and_return([arping_cmd, mac])
|
119
|
+
commands.should_receive(:arping).with(ip, 1).and_return([arping_cmd, mac])
|
110
120
|
scanner.scan_ip(ip)
|
111
121
|
end
|
112
122
|
|
@@ -129,7 +139,7 @@ describe Presence::Scanner do
|
|
129
139
|
|
130
140
|
context 'with a non-existent IP' do
|
131
141
|
before {
|
132
|
-
commands.stub(:arping).with(ip).and_return([arping_cmd, 'No such jeaun'])
|
142
|
+
commands.stub(:arping).with(ip, 1).and_return([arping_cmd, 'No such jeaun'])
|
133
143
|
}
|
134
144
|
|
135
145
|
it 'does not dispatch a mac_found event' do
|
metadata
CHANGED
@@ -1,80 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jason Wadsworth
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
type: :development
|
15
|
+
name: rake
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ~>
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 0.9.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
29
|
version: 0.9.2
|
29
|
-
name: rake
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
32
|
-
type: :development
|
31
|
+
name: rspec
|
33
32
|
requirement: !ruby/object:Gem::Requirement
|
34
33
|
none: false
|
35
34
|
requirements:
|
36
35
|
- - ~>
|
37
36
|
- !ruby/object:Gem::Version
|
38
37
|
version: 2.11.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
39
40
|
version_requirements: !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
43
|
- - ~>
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: 2.11.0
|
45
|
-
name: rspec
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
48
|
-
type: :development
|
47
|
+
name: cane
|
49
48
|
requirement: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
52
51
|
- - ~>
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: 2.3.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
55
56
|
version_requirements: !ruby/object:Gem::Requirement
|
56
57
|
none: false
|
57
58
|
requirements:
|
58
59
|
- - ~>
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: 2.3.0
|
61
|
-
name: cane
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
|
64
|
-
type: :development
|
63
|
+
name: simplecov
|
65
64
|
requirement: !ruby/object:Gem::Requirement
|
66
65
|
none: false
|
67
66
|
requirements:
|
68
67
|
- - ~>
|
69
68
|
- !ruby/object:Gem::Version
|
70
69
|
version: 0.7.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
71
72
|
version_requirements: !ruby/object:Gem::Requirement
|
72
73
|
none: false
|
73
74
|
requirements:
|
74
75
|
- - ~>
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: 0.7.1
|
77
|
-
name: simplecov
|
78
78
|
description: Monitors the local network for presence of network clients by MAC address.
|
79
79
|
email:
|
80
80
|
- jdwadsworth@gmail.com
|