hooray 0.1.5 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +14 -0
- data/Guardfile +22 -0
- data/MIT-LICENSE +20 -0
- data/hooray.gemspec +29 -0
- data/lib/hooray/cli.rb +17 -5
- data/lib/hooray/seek.rb +24 -20
- data/lib/hooray/settings.rb +8 -4
- data/lib/hooray/settings/devices.yml +1 -1
- data/lib/hooray/settings/services.yml +4 -8
- data/lib/hooray/version.rb +1 -1
- data/spec/hooray/node_spec.rb +6 -4
- data/spec/hooray/seek_spec.rb +0 -2
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b6ba8e1a0e98fdcef75ae3803ecc84d430a14e7
|
4
|
+
data.tar.gz: 9191775fb0feb7c4137f8ddea30d3442cb387bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af30c78db97d13f77c137eb3a7e38c2129f36ea8f52f6c353406b2d60d247552e3ff35b1f0c8fc4210c036ff692d83716ddfd6f84e37f53bf9deadc44acb3eac
|
7
|
+
data.tar.gz: 21f46636f41389ab80335963bb262fb588858bcca24ce0b6bba3e80d7d86c9150e3e59a9fddf387cfaf076d7c97f26674c55fc118e18fd6eec940487dfe48434
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
2
|
+
# rspec may be run, below are examples of the most common uses.
|
3
|
+
# * bundler: 'bundle exec rspec'
|
4
|
+
# * bundler binstubs: 'bin/rspec'
|
5
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
6
|
+
# installed the spring binstubs per the docs)
|
7
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
8
|
+
# * 'just' rspec: 'rspec'
|
9
|
+
|
10
|
+
# guard :rubocop do
|
11
|
+
guard :rubocop, all_on_start: false, keep_failed: false, cli: ['-D'] do
|
12
|
+
watch(%r{.+\.rb$})
|
13
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
14
|
+
end
|
15
|
+
|
16
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
17
|
+
watch(%r{^spec/.+_spec\.rb$})
|
18
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
|
+
watch(/^generators\/(.+)\.rb$/) { |_m| 'spec/schemaless/worker_spec' }
|
20
|
+
|
21
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
22
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007-2008 Andreas Neuhaus <zargony@zargony.com>
|
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/hooray.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'hooray/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'hooray'
|
8
|
+
s.version = Hooray::VERSION
|
9
|
+
|
10
|
+
s.authors = ['Marcos Piccinini']
|
11
|
+
s.homepage = 'http://github.com/nofxx/hooray'
|
12
|
+
s.email = 'x@nofxx.com'
|
13
|
+
s.description = 'Find all those devices connected in LAN'
|
14
|
+
s.summary = 'Find devices connected in LAN'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.executables = ['hoo']
|
18
|
+
s.default_executable = 'hoo'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.add_dependency 'thor'
|
25
|
+
s.add_dependency 'paint'
|
26
|
+
s.add_dependency 'macaddr'
|
27
|
+
s.add_dependency 'net-ping'
|
28
|
+
s.add_dependency 'table_print'
|
29
|
+
end
|
data/lib/hooray/cli.rb
CHANGED
@@ -2,7 +2,7 @@ require 'thor'
|
|
2
2
|
|
3
3
|
module Hooray
|
4
4
|
# Nice cli
|
5
|
-
class CLI < Thor
|
5
|
+
class CLI < Thor # rubocop:disable Metrics/ClassLength
|
6
6
|
class_option :verbose, type: :boolean, aliases: :v
|
7
7
|
class_option :network, type: :string, aliases: :n
|
8
8
|
|
@@ -37,13 +37,19 @@ module Hooray
|
|
37
37
|
|
38
38
|
LONG
|
39
39
|
def list(*filter)
|
40
|
-
|
40
|
+
puts sweep = Seek.new(options[:network], *filter)
|
41
|
+
if sweep.nodes.empty?
|
41
42
|
pa "No results for filter #{filter.join(' ')}", :red
|
42
43
|
else
|
43
|
-
print_table(nodes)
|
44
|
+
print_table(sweep.nodes)
|
44
45
|
end
|
45
46
|
puts
|
46
47
|
end
|
48
|
+
# no_commands do
|
49
|
+
# alias_method :lsit, :list
|
50
|
+
# alias_method :lits, :list
|
51
|
+
# alias_method :all, :list
|
52
|
+
# end
|
47
53
|
|
48
54
|
desc 'watch FILTER', 'watch in realtime FILTER'
|
49
55
|
long_desc <<-LONG
|
@@ -98,15 +104,21 @@ module Hooray
|
|
98
104
|
|
99
105
|
def print_table(nodes)
|
100
106
|
return if nodes.empty?
|
107
|
+
puts
|
101
108
|
if nodes.first.ports.empty?
|
102
109
|
tp nodes, :name, :ip, :mac
|
103
110
|
else
|
104
111
|
tp nodes, :name, :ip, :mac, :ports
|
105
112
|
end
|
106
113
|
puts '---'
|
114
|
+
summary(nodes)
|
115
|
+
end
|
116
|
+
|
117
|
+
def summary(nodes)
|
107
118
|
took = (Time.now - @start).round(2)
|
108
|
-
|
109
|
-
|
119
|
+
message = "#{nodes.count} device"
|
120
|
+
message += 's' if nodes.size > 1
|
121
|
+
pa "#{message} @ #{Time.now} #{took}s", '#777', :bold
|
110
122
|
end
|
111
123
|
|
112
124
|
def method_missing(*params)
|
data/lib/hooray/seek.rb
CHANGED
@@ -7,6 +7,7 @@ module Hooray
|
|
7
7
|
|
8
8
|
NET_MASK = 24
|
9
9
|
TIMEOUT = 1
|
10
|
+
RANGE_REGEX = /\.{2,3}/
|
10
11
|
|
11
12
|
def initialize(network = nil, *params)
|
12
13
|
@scan = {}
|
@@ -15,44 +16,44 @@ module Hooray
|
|
15
16
|
config_filters params
|
16
17
|
end
|
17
18
|
|
18
|
-
def config_network(
|
19
|
-
|
20
|
-
@network = IPAddr.new(param)
|
21
|
-
else
|
22
|
-
@network = Hooray::Local.mask
|
23
|
-
end
|
19
|
+
def config_network(str)
|
20
|
+
@network = str && !str.empty? ? IPAddr.new(str) : Hooray::Local.mask
|
24
21
|
end
|
25
22
|
|
26
23
|
def config_filters(params)
|
27
24
|
return if params.empty?
|
28
|
-
|
29
|
-
|
25
|
+
# Map services 'foo' -> 3000 udp
|
26
|
+
params.map! { |o| Settings.service(o) || o }
|
27
|
+
# Map Ranges 1..3 -> [1,2,3]
|
28
|
+
params.map! do |o|
|
29
|
+
next o unless o =~ RANGE_REGEX
|
30
|
+
Range.new(*o.split(RANGE_REGEX)).to_a
|
31
|
+
end
|
32
|
+
numbers, words = params.flatten.partition { |s| s.to_s =~ /\d+/ }
|
33
|
+
@ports, @protocol = numbers.map(&:to_i), words.join
|
30
34
|
end
|
35
|
+
|
31
36
|
#
|
32
37
|
# Map results to @nodes << Node.new()
|
33
38
|
#
|
34
|
-
# BUG: sometimes ping returns true
|
35
|
-
# When you run list consecutively. Pretty weird!
|
36
|
-
# So we need to remove those without mac
|
37
39
|
def nodes
|
38
40
|
return @nodes if @nodes
|
39
41
|
@nodes = sweep.map do |k, v|
|
40
42
|
Node.new(ip: k, mac: Hooray::Local.arp_table[k.to_s], ports: v)
|
41
|
-
end.reject { |n| n.mac.nil? } # remove those without mac
|
43
|
+
end # .reject { |n| n.mac.nil? } # remove those without mac
|
42
44
|
end
|
43
45
|
alias_method :devices, :nodes
|
44
46
|
|
47
|
+
#
|
48
|
+
# Decide how to ping
|
45
49
|
def ping_class
|
46
50
|
return Net::Ping::External unless ports
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
Net::Ping::TCP
|
51
|
-
# elsif (serv = Settings.service(@words.join))
|
52
|
-
# @ports = serv.values
|
53
|
-
end
|
51
|
+
return Net::Ping::TCP unless @protocol =~ /tcp|udp|http|wmi/
|
52
|
+
Net::Ping.const_get(@protocol.upcase)
|
54
53
|
end
|
55
54
|
|
55
|
+
#
|
56
|
+
# Creates a bot per port on IP
|
56
57
|
def scan_bot(ip)
|
57
58
|
(ports || [nil]).each do |port|
|
58
59
|
@bots << Thread.new do
|
@@ -73,8 +74,11 @@ module Hooray
|
|
73
74
|
scan_bot(ip)
|
74
75
|
end
|
75
76
|
@bots.each(&:join)
|
76
|
-
puts
|
77
77
|
@scan.reject! { |_k, v| v.empty? }
|
78
78
|
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
"Seek #{network} #{ports}"
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
data/lib/hooray/settings.rb
CHANGED
@@ -37,14 +37,18 @@ module Hooray
|
|
37
37
|
out
|
38
38
|
end
|
39
39
|
|
40
|
-
def devices
|
41
|
-
@devices ||= {}
|
42
|
-
end
|
43
|
-
|
44
40
|
def device(mac)
|
45
41
|
devices[mac.to_sym] || devices[mac.to_s]
|
46
42
|
end
|
47
43
|
|
44
|
+
def service(name)
|
45
|
+
services[name.to_sym] || services[name.to_s]
|
46
|
+
end
|
47
|
+
|
48
|
+
def devices
|
49
|
+
@devices ||= {}
|
50
|
+
end
|
51
|
+
|
48
52
|
def services
|
49
53
|
@services ||= {}
|
50
54
|
end
|
data/lib/hooray/version.rb
CHANGED
data/spec/hooray/node_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Node' do
|
4
|
-
|
5
4
|
it 'should have ip' do
|
6
5
|
expect(Node.new(ip: '10.1.1.1').ip).to eq('10.1.1.1')
|
7
6
|
end
|
@@ -18,10 +17,13 @@ describe 'Node' do
|
|
18
17
|
expect(Node.new(name: 'my iphone').name).to eq('my iphone')
|
19
18
|
end
|
20
19
|
|
21
|
-
it 'should have ports' do
|
20
|
+
it 'should have ports as string' do
|
21
|
+
expect(Node.new(ports: [22]).ports).to eq('22')
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'should have
|
24
|
+
it 'should have compare methods' do
|
25
|
+
node1 = Node.new(ip: '10.1.1.1')
|
26
|
+
node2 = Node.new(ip: '10.1.1.1')
|
27
|
+
expect([node1] - [node2]).to be_empty
|
25
28
|
end
|
26
|
-
|
27
29
|
end
|
data/spec/hooray/seek_spec.rb
CHANGED
@@ -11,7 +11,6 @@ describe 'Seek' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'Query' do
|
14
|
-
|
15
14
|
it 'should default to ICMP without port' do
|
16
15
|
expect(Seek.new('').ping_class).to eq(Net::Ping::External)
|
17
16
|
end
|
@@ -27,6 +26,5 @@ describe 'Seek' do
|
|
27
26
|
it 'should accept protocol with port' do
|
28
27
|
expect(Seek.new('', '80', 'udp').ping_class).to eq(Net::Ping::UDP)
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hooray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -87,9 +87,16 @@ executables:
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".coveralls.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Guardfile
|
95
|
+
- MIT-LICENSE
|
90
96
|
- README.md
|
91
97
|
- Rakefile
|
92
98
|
- bin/hoo
|
99
|
+
- hooray.gemspec
|
93
100
|
- lib/hooray.rb
|
94
101
|
- lib/hooray/cli.rb
|
95
102
|
- lib/hooray/local.rb
|
@@ -129,5 +136,8 @@ rubygems_version: 2.4.3
|
|
129
136
|
signing_key:
|
130
137
|
specification_version: 4
|
131
138
|
summary: Find devices connected in LAN
|
132
|
-
test_files:
|
139
|
+
test_files:
|
140
|
+
- spec/hooray/node_spec.rb
|
141
|
+
- spec/hooray/seek_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
133
143
|
has_rdoc:
|