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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b25f88e85a64e4c69b0f9329a054dc35bf0c35
4
- data.tar.gz: 3c57622a6c1f3aa1258d910f9c8c36f187c0dbad
3
+ metadata.gz: 2b6ba8e1a0e98fdcef75ae3803ecc84d430a14e7
4
+ data.tar.gz: 9191775fb0feb7c4137f8ddea30d3442cb387bcf
5
5
  SHA512:
6
- metadata.gz: 3cf3772c8c087e120bfcefbc06a6a081d1040a932b941f6a5c95127045ccb9f051064afd6d85269ea65f8d2f394306399d8d65922eb75186fb29bec52d1332b0
7
- data.tar.gz: 584abd5fe3d7c4ae8a017f0abb241f87123003346335f6bef794fde4cd775062ca1674d4653484a8a603894f7290c4078c7e4ea24216560aa1325b0bc1df0681
6
+ metadata.gz: af30c78db97d13f77c137eb3a7e38c2129f36ea8f52f6c353406b2d60d247552e3ff35b1f0c8fc4210c036ff692d83716ddfd6f84e37f53bf9deadc44acb3eac
7
+ data.tar.gz: 21f46636f41389ab80335963bb262fb588858bcca24ce0b6bba3e80d7d86c9150e3e59a9fddf387cfaf076d7c97f26674c55fc118e18fd6eec940487dfe48434
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ coverage
3
+ rdoc
4
+ pkg
5
+ .bundle
6
+ Gemfile.lock
7
+ *.gem
8
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ - rbx-2
7
+ - ruby-head
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: rbx-2
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'pry'
6
+ gem 'coveralls'
7
+ gem 'rake'
8
+ gem 'rspec', '>= 3'
9
+ gem 'rubocop'
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'guard-rubocop'
13
+
14
+ gem 'coveralls', require: false if ENV['CI']
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
- if (nodes = Seek.new(options[:network], *filter).nodes).empty?
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
- count_plural = nodes.size > 1 ? 's' : ''
109
- pa "#{nodes.count} device#{count_plural} @ #{Time.now} #{took}s", '#777', :bold
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(param)
19
- if param && !param.empty?
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
- numbers, @words = params.flatten.partition { |s| s =~ /\d+/ }
29
- @ports = numbers.map(&:to_i)
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
- if @words && @words.join =~ /tcp|udp|http|wmi/
48
- Net::Ping.const_get(@words.join.upcase)
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
@@ -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
@@ -3,7 +3,7 @@
3
3
  # :MAC: | NAME | Don't forget the :double: colons on :mac:
4
4
  # :01:02:03:04:05:06: Nice host
5
5
  #
6
- # Regexes ok, don't forget :double: colons!
6
+ # Partial (brand codes) ok, don't forget :double: colons!
7
7
  #
8
8
  # :01:02:03: Some big brand of mobiles
9
9
  #
@@ -1,11 +1,7 @@
1
1
  # Services List
2
2
  #
3
- # protocol:
4
- # port: name
3
+ # name: PORT <tcp>
5
4
  #
6
- tcp:
7
- 3000: Rails Dev
8
- 27017..27030: Mongos
9
-
10
- udp:
11
- 777: Jackpot Machines
5
+ rails: 3000
6
+ mongos: 27017..27027
7
+ jackpot: 777 udp
@@ -1,4 +1,4 @@
1
1
  # Hooray version
2
2
  module Hooray
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.8'
4
4
  end
@@ -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 hoops' do
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
@@ -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.5
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-12 00:00:00.000000000 Z
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: