findme 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/README.md +24 -2
- data/lib/findme.rb +14 -1
- data/lib/findme/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,10 @@ Install
|
|
9
9
|
sudo apt-get install avahi-utils avahi-daemon libnss-mdns
|
10
10
|
gem install findme
|
11
11
|
|
12
|
+
Enable normal user to use this gem (first time):
|
13
|
+
|
14
|
+
sudo chmod a+w /etc/avahi/services/
|
15
|
+
|
12
16
|
Example
|
13
17
|
-------
|
14
18
|
|
@@ -24,10 +28,10 @@ More advanced Example
|
|
24
28
|
on server:
|
25
29
|
|
26
30
|
require 'findme'
|
27
|
-
|
31
|
+
Findme.cleanup
|
28
32
|
Findme.register "findme", 1337
|
29
33
|
|
30
|
-
on client:
|
34
|
+
on client -> client.rb:
|
31
35
|
|
32
36
|
require 'findme'
|
33
37
|
|
@@ -35,9 +39,27 @@ on client:
|
|
35
39
|
services = Findme.discover
|
36
40
|
services.select{|s| s.service == "_#{SERVICE}._tcp"}.each{|s| puts "#{s.ip}:#{s.port}"}
|
37
41
|
|
42
|
+
on client discover latest and earliest -> client_earliest_latest.rb:
|
43
|
+
|
44
|
+
require 'findme'
|
45
|
+
require 'pp'
|
46
|
+
|
47
|
+
SERVICE = "findme"
|
48
|
+
h = Findme.discover_only_earliest
|
49
|
+
h.select{|k,s| s.service == "_#{SERVICE}._tcp"}.each{|k,s| puts "#{k}|#{s.ip}:#{s.port}:#{s.txt}"}
|
50
|
+
|
51
|
+
|
52
|
+
h = Findme.discover_only_latest
|
53
|
+
h.select{|k,s| s.service == "_#{SERVICE}._tcp"}.each{|k,s| puts "#{k}|#{s.ip}:#{s.port}:#{s.txt}"}
|
54
|
+
|
55
|
+
|
38
56
|
results on client.rb:
|
39
57
|
|
40
58
|
~ > ruby client.rb
|
41
59
|
fe80::a00:27ff:feeb:xxxx:1337
|
42
60
|
192.168.xx.xx:1337
|
43
61
|
|
62
|
+
|
63
|
+
~ > ruby client_earliest_latest.rb
|
64
|
+
_findme._tcp|192.168.10.xxx:1337:"findme_startup_time=1346228166"
|
65
|
+
_findme._tcp|192.168.10.yyy:1337:"findme_startup_time=1346229066"
|
data/lib/findme.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
module Findme
|
2
2
|
|
3
3
|
AVAHI_SERVICE_DIR = "/etc/avahi/services/"
|
4
4
|
AVAHI_BROWSE = "/usr/bin/avahi-browse"
|
@@ -96,6 +96,15 @@ class Findme
|
|
96
96
|
h_out
|
97
97
|
end
|
98
98
|
|
99
|
+
def self.discover_service(service, ip=nil)
|
100
|
+
services = discover
|
101
|
+
|
102
|
+
result = services.detect {|x| x.service == "_#{service}._tcp" && x.ip == ip}
|
103
|
+
return result if result #here we choose best match if previous is this ip
|
104
|
+
#todo, using other factor to determine rank algorithm
|
105
|
+
return services.detect {|x| x.service == "_#{service}._tcp"}[0]
|
106
|
+
end
|
107
|
+
|
99
108
|
|
100
109
|
def self.discover
|
101
110
|
res = `avahi-browse -arpt`
|
@@ -165,4 +174,8 @@ end
|
|
165
174
|
class AvahiService
|
166
175
|
attr_accessor :eth, :ipv4, :ip, :hosttxt, :hostname, :port, :txt, :service
|
167
176
|
|
177
|
+
def ip_and_port
|
178
|
+
[ip, port]
|
179
|
+
end
|
180
|
+
|
168
181
|
end
|
data/lib/findme/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: findme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: find neighborhood host and services with avahi / avahi-daemon. run this
|
15
15
|
for the first time to allow normal user to register services `sudo chmod a+w /etc/avahi/services/`
|