hooray 0.0.7 → 0.0.9

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: 70895187b462c2363960525378f2616fb1d25a11
4
- data.tar.gz: 1a5bf065e8f66a315e703c55ac39b25131b33803
3
+ metadata.gz: fe7164b3a564dbaca837819687bd21014d190564
4
+ data.tar.gz: 61f8f487a6570d32013f26895f0015060147abd8
5
5
  SHA512:
6
- metadata.gz: f76544c3f668672549a984f31b831fa9cf116e23bb9a3e38f419cb3903750fafdf4d698be69dd4dec5a793db800c709625ae706e9c592ac86f4495801293f75f
7
- data.tar.gz: 1323add01b3372288b79e7df6fe3cc32f327d46ec0470eca9b24f601e260203f11ae9e5609a8b59a94abc36ea7fee44e3a11d7cfc46c2eb663e1353f88601371
6
+ metadata.gz: 63de61f3a84464c2b0c3370fc9de0398b09d8927a097ff090b6305ae74ffb46f87f83fc8fc776bff7debf5e0002e01d19143f939f7855a5eb40fcaef7b6bdff6
7
+ data.tar.gz: 9ac80ce35d020fe3cc43576738e43ae75e7a458311882fea80867273fb386af99a622215a678d61d5aa21430ad2278e2ad072421499073dff3faa5c93e56462f
data/README.md CHANGED
@@ -24,10 +24,11 @@ LG Electronics | 192.168.1.79 | cc:fa:XX:XX:XX:XX
24
24
  TP-Link | 192.168.1.253 | f8:d1:XX:XX:XX:XX
25
25
  Siemens Subscriber Networks | 192.168.1.254 | 00:0b:XX:XX:XX:XX
26
26
  ---
27
- 8 devices @ 2014-12-11 13:32:04 -0200 2.85s
27
+ 8 devices @ 2014-12-11 13:32:04 -0200 2.27s
28
28
  ```
29
29
 
30
- Find running services:
30
+
31
+ ## Find running services
31
32
 
32
33
  ```
33
34
  hoo list web
@@ -35,7 +36,11 @@ hoo list web
35
36
  ```
36
37
  NAME | IP | MAC
37
38
  ------------------|--------------|------------------
39
+ dsl modem | 192.168.1.1 | 64:a3:XX:XX:XX:XX
40
+ test server | 192.168.1.75 | 64:a3:XX:XX:XX:XX
38
41
  nofxx desktop | 192.168.1.77 | 64:a3:XX:XX:XX:XX
42
+ ---
43
+ 3 devices @ 2014-12-11 19:23:11 -0200 1.10s
39
44
  ```
40
45
 
41
46
  Or simply by ports:
@@ -46,25 +51,45 @@ hoo list 80
46
51
  hoo list 6777 udp
47
52
  ```
48
53
 
49
- Monitor:
54
+ ## Monitor
50
55
 
51
56
  ```
52
57
  hoo watch
53
58
  ```
54
59
  ```
55
60
  New nodes @ 2014-12-11 13:53:06 -0200
56
- NAME | IP | MAC
57
- -------------|--------------|------------------
58
- iPhone nofxx | 192.168.1.76 | 64:a3:XX:XX:XX:XX
61
+ NAME | IP | MAC
62
+ -----------|--------------|------------------
63
+ myphone | 192.168.1.76 | 64:a3:XX:XX:XX:XX
64
+ ```
65
+
66
+
67
+ ## Use another program
68
+
59
69
  ```
70
+ hoo ssh myphone
71
+ ```
72
+
73
+ Will execute: `ssh <ip of myphone>`
74
+
75
+ You can use any program, not just ssh.
76
+
77
+
78
+ ## Use as a lib
60
79
 
61
- Use as a lib:
62
80
  ```
63
81
  require 'hooray'
64
82
  Hooray::Seek.lan(port, protocol).devices
65
83
  Hooray::Seek.new(network, port, protocol).devices
66
84
  ```
67
85
 
86
+ * Nil port means ICMP ping.
87
+ * Protocol always defaults to :tcp.
88
+ * Network defaults to LAN IP 24 bits masked.
89
+
90
+ Possible protocols: tcp, udp, http, wmi & icmp (requires root).
91
+
92
+
68
93
  ## Why?
69
94
 
70
95
  Bind macs or fix IP's is also boring and a per device work.
@@ -89,3 +114,7 @@ services.yml regex list ports to names you recognize.
89
114
 
90
115
  * Ruby net-ping gem.
91
116
  * Nmap`s mac precompiled prefixes.
117
+
118
+
119
+ Hooray should work on UNIX based systems.
120
+ Tested in Linux and OS X.
data/bin/hoo CHANGED
@@ -4,6 +4,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  require 'hooray'
5
5
 
6
6
  puts
7
- puts ' Hooray!'
7
+ puts ' Hooray!'
8
8
 
9
9
  Hooray::CLI.start(ARGV)
@@ -105,8 +105,10 @@ module Hooray
105
105
  puts "Do you want to `#{params.first}` to a device?"
106
106
  puts "Use #{ARGV.first} #{params.first} <device name>"
107
107
  when 2 then
108
- command, *device = *params
109
- system "#{command} "
108
+ command, name = params
109
+ device = Hooray::Seek.new.devices.find { |d| d.name == name }
110
+ return puts("Could not find '#{name}'") unless device
111
+ system "#{command} #{device.ip}"
110
112
  else super
111
113
  end
112
114
  end
@@ -7,20 +7,20 @@ module Hooray
7
7
  @ip = params[:ip]
8
8
  @mac = params[:mac]
9
9
  @mac ||= Mac.addr if @ip == Seek.my_lan_ip
10
- set_name
10
+ @name = params[:name] || find_name
11
11
  end
12
12
 
13
- def set_name
13
+ def find_name
14
14
  return unless mac
15
- if [Mac.addr].flatten.include?(mac)
16
- @name = Socket.gethostname
15
+ if [Mac.addr].flatten.include?(mac) # Hack until macaddr get fix
16
+ Socket.gethostname
17
17
  else
18
- @name = Settings.device(mac) || Settings.family(mac)
18
+ Settings.device(mac) || Settings.manufacturer(mac)
19
19
  end
20
20
  end
21
21
 
22
22
  def to_ip
23
- Addrinfo.ip(ip)
23
+ IPAddr.new(ip)
24
24
  end
25
25
 
26
26
  def <=>(other)
@@ -10,17 +10,32 @@ module Hooray
10
10
 
11
11
  def initialize(network = nil, *params)
12
12
  @network = network || Seek.local_mask
13
- unless params.empty?
14
- ports, words = params.flatten.partition { |s| s =~ /\d+/ }
15
- @ports = ports.map(&:to_i).first # TODO
16
- @protocol = words.select { |w| w =~ /udp|tcp/ }.join
17
- end
13
+ set_query(params)
14
+ set_nodes
15
+ end
16
+ alias_method :devices, :nodes
18
17
 
18
+ #
19
+ # Form need params based on user input
20
+ #
21
+ def set_query(params)
22
+ return if params.empty?
23
+ ports, words = params.flatten.partition { |s| s =~ /\d+/ }
24
+ @ports = ports.map(&:to_i).first # TODO
25
+ @protocol = words.select { |w| w =~ /udp|tcp/ }.join
26
+ end
27
+
28
+ #
29
+ # Map results to @nodes << Node.new()
30
+ #
31
+ # BUG: sometimes ping returns true
32
+ # When you run list consecutively. Pretty weird!
33
+ # So we need to remove those without mac
34
+ def set_nodes
19
35
  @nodes = ping.sort.map do |n|
20
36
  Node.new(ip: n, mac: arp_table[n.to_s]) # , name: find_name(n))
21
- end
37
+ end.reject { |n| n.mac.nil? } # remove those without mac
22
38
  end
23
- alias_method :devices, :nodes
24
39
 
25
40
  def ping_class
26
41
  return Net::Ping::External unless @protocol
@@ -4,10 +4,10 @@ module Hooray
4
4
  CONFIG_DIR = ENV['HOME'] + '/.hooray/'
5
5
 
6
6
  class << self
7
- attr_accessor :all, :services, :devices, :macs
7
+ attr_accessor :all
8
8
 
9
9
  def no_config_folder
10
- puts "No config folder, run `#{$PROGRAM_NAME} init`"
10
+ pa "No config folder, run `#{$PROGRAM_NAME} init`", :red
11
11
  puts
12
12
  exit 1
13
13
  end
@@ -37,15 +37,27 @@ module Hooray
37
37
  out
38
38
  end
39
39
 
40
+ def devices
41
+ @devices ||= {}
42
+ end
43
+
40
44
  def device(mac)
41
- devices ||= {}
42
45
  devices[mac.to_sym] || devices[mac.to_s]
43
46
  end
44
47
 
45
- def family(mac)
48
+ def services
49
+ @services ||= {}
50
+ end
51
+
52
+ def manufacturers
53
+ @macs || {}
54
+ end
55
+
56
+ def manufacturer(mac)
46
57
  prefix = mac.to_s.gsub(':', '')[0, 6].upcase
47
- macs[prefix]
58
+ manufacturers[prefix]
48
59
  end
60
+ alias_method :family, :manufacturer
49
61
 
50
62
  def all
51
63
  @all ||= {}
@@ -1,4 +1,4 @@
1
1
  # Hooray version
2
2
  module Hooray
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.9'
4
4
  end
@@ -1,16 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Nodek' do
3
+ describe 'Node' do
4
4
 
5
5
  it 'should have ip' do
6
+ expect(Node.new(ip: '10.1.1.1').ip).to eq('10.1.1.1')
7
+ end
8
+
9
+ it 'should have a #to_ip' do
10
+ expect(Node.new(ip: '10.1.1.1').to_ip).to be_a(IPAddr)
6
11
  end
7
12
 
8
- it 'should have mac address' do
9
13
 
14
+ it 'should have mac address' do
15
+ expect(Node.new(mac: 'aa:cc:dd:ee:ff:gg').mac).to eq('aa:cc:dd:ee:ff:gg')
10
16
  end
11
17
 
12
18
  it 'should have name' do
13
-
19
+ expect(Node.new(name: 'my iphone').name).to eq('my iphone')
14
20
  end
15
21
 
16
22
  it 'should have ports' do
@@ -9,6 +9,9 @@ end
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
11
 
12
+ require 'hooray'
13
+ include Hooray
14
+
12
15
  if ENV['CI']
13
16
  require 'coveralls'
14
17
  Coveralls.wear!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini