auser-columbus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ari Lerner
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/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = columbus
2
+
3
+ Columbus is a dns-sd discovery tool. You can both broadcast presence with the server tool and look for broadcasts on your network as well!
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Ari Lerner. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
data/bin/columbus ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require ::File.dirname(__FILE__) + "/../lib/columbus"
4
+ require 'git-style-binary/command'
5
+
6
+ GitStyleBinary.primary do
7
+ @theme = :short
8
+
9
+ version "Columbus"
10
+ banner <<-EOS
11
+ Usage: #{$0} #{all_options_string} COMMAND [ARGS]
12
+
13
+ The #{$0} subcommands commands are:
14
+ \#{GitStyleBinary.pretty_known_subcommands.join(" ")}
15
+
16
+ See '#{$0} help COMMAND' for more information on a specific command.
17
+ EOS
18
+
19
+ run do |command|
20
+ puts "You need to type a subcommand. Use -h for more"
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require ::File.dirname(__FILE__) + "/../lib/columbus"
4
+ require 'git-style-binary/command'
5
+
6
+ GitStyleBinary.command do
7
+ @theme = :short
8
+
9
+ version "Columbus client"
10
+ banner <<-EOS
11
+ Usage: #{$0} #{all_options_string} COMMAND [ARGS]
12
+ EOS
13
+
14
+ opt :discover_type, "Type of discovery message", :default => nil
15
+ opt :query, "Query to perform on the service"
16
+
17
+ run do |command|
18
+
19
+ Columbus::Client.discover_type = command[:discover_type] unless command[:discover_type].nil?
20
+
21
+ # Columbus::Client.list
22
+ Columbus::Client.service_list.each do |s|
23
+ if command[:query]
24
+ puts s.send(command[:query].to_sym)
25
+ else
26
+ puts "#{s.name}\t#{s.host}\t#{s.port}\t#{s.description}"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require ::File.dirname(__FILE__) + "/../lib/columbus"
4
+ require 'git-style-binary/command'
5
+
6
+ GitStyleBinary.command do
7
+ @theme = :short
8
+
9
+ version "Columbus"
10
+ banner <<-EOS
11
+ Usage: #{$0} #{all_options_string} COMMAND [ARGS]
12
+ EOS
13
+
14
+ opt :interface, "The interface to pull from", :default => "vmnet8"
15
+ opt :name, "Name to broadcast", :type => String
16
+ opt :description, "Description to broadcast", :type => String
17
+
18
+ run do |command|
19
+ interface = command[:interface]
20
+
21
+ Columbus::Server.name = command[:name] unless command[:name].nil?
22
+ Columbus::Server.description = command[:description] unless command[:description].nil?
23
+
24
+ Columbus::Server.announce(interface)
25
+ end
26
+ end
data/lib/columbus.rb ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/columbus")
2
+ require "rubygems"
3
+ require "dnssd"
4
+ require "server"
5
+ require "client"
6
+
7
+ module Columbus
8
+ end
@@ -0,0 +1,64 @@
1
+ =begin rdoc
2
+ Columbus Dns-sd lookup
3
+
4
+ Client
5
+ =end
6
+ require "set"
7
+
8
+ module Columbus
9
+ class FoundService
10
+ attr_accessor :name, :host, :port, :description
11
+ def initialize(name, host, port, description)
12
+ @name = name
13
+ @host = host
14
+ @port = port
15
+ @description = description
16
+ end
17
+ end
18
+ class Client
19
+ class << self
20
+
21
+ attr_accessor :discover_type
22
+
23
+ def discover_type
24
+ @discover_type ||= "_presence._tcp"
25
+ end
26
+
27
+ def discover(timeout=5)
28
+ waiting_thread = Thread.current
29
+
30
+ dns = DNSSD.browse discover_type do |reply|
31
+ DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
32
+ service = FoundService.new(reply.name,
33
+ resolve_reply.target,
34
+ resolve_reply.port,
35
+ (resolve_reply.text_record['description'].to_s rescue ""))
36
+ begin
37
+ yield service
38
+ rescue Done
39
+ waiting_thread.run
40
+ end
41
+ end
42
+ end
43
+ puts "Gathering for up to #{timeout} seconds for #{discover_type}..."
44
+ sleep timeout
45
+ dns.stop
46
+ end
47
+
48
+ def service_list
49
+ list = Set.new
50
+ discover { |obj| list << obj }
51
+ return list
52
+ end
53
+
54
+ def list
55
+ service_list.each do |service|
56
+ puts "=== #{service.name} on #{service.host}:#{service.port} ==="
57
+ puts " found #{service.name}"
58
+ puts " #{service.description}"
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,50 @@
1
+ =begin rdoc
2
+ Columbus Dns-sd lookup
3
+
4
+ Server
5
+ =end
6
+ module Columbus
7
+ class Server
8
+ class << self
9
+
10
+ attr_accessor :name, :description
11
+
12
+ def announce(interface="vmnet8", t="_presence", proto="tcp", port=9419)
13
+ @interface = interface
14
+ while true do
15
+ DNSSD.register(name, "#{t}._#{proto}", 'local', port, text_record.encode) do |rr|
16
+ vprint "."
17
+ end
18
+ sleep(90)
19
+ end
20
+ end
21
+
22
+ def text_record
23
+ @text_record = DNSSD::TextRecord.new
24
+ @text_record['description'] = @description || map_ip_to_interface[@interface]
25
+ @text_record
26
+ end
27
+
28
+ def map_ip_to_interface(str=ifconfig)
29
+ out = {}
30
+ @current_interface = nil
31
+ str.split("\n").collect do |line|
32
+ iface = line.match(/^([a-zA-Z]+(\d)+)(:)?/)
33
+ @current_interface = iface.captures.first.to_s if iface
34
+
35
+ ip = line.match(/inet (addr:)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i)
36
+ if ip && @current_interface
37
+ ip = ip.captures.compact.to_s.gsub(/addr:/, '')
38
+ out.merge!({@current_interface => ip})
39
+ end
40
+ end
41
+ out
42
+ end
43
+
44
+ def ifconfig
45
+ %x{ifconfig}
46
+ end
47
+
48
+ end
49
+ end
50
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class ColumbusTest < Test::Unit::TestCase
4
+ should "be able to get the ip" do
5
+ assert_equal Columbus::Server.map_ip_to_interface.class, Hash
6
+ end
7
+ %w(mac vmware).each do |n|
8
+ should "be able to parse data on #{n}" do
9
+ data = open(::File.dirname(__FILE__) + "/fixtures/ifconfig-#{n}").read
10
+ assert_equal Columbus::Server.map_ip_to_interface(data)["vmnet1"], "172.16.66.1"
11
+ end
12
+ end
13
+ should "have an text_record" do
14
+ assert_equal Columbus::Server.text_record.class, DNSSD::TextRecord
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
2
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
3
+ inet 127.0.0.1 netmask 0xff000000
4
+ inet6 ::1 prefixlen 128
5
+ gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
6
+ stf0: flags=0<> mtu 1280
7
+ en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
8
+ inet6 fe80::223:dfff:fe7f:55e4%en0 prefixlen 64 scopeid 0x4
9
+ inet 10.45.10.228 netmask 0xfffffe00 broadcast 10.45.11.255
10
+ ether 00:23:df:7f:55:e4
11
+ media: autoselect (100baseTX <full-duplex>) status: active
12
+ supported media: none autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,flow-control> 10baseT/UTP <full-duplex,hw-loopback> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,flow-control> 100baseTX <full-duplex,hw-loopback> 1000baseT <full-duplex> 1000baseT <full-duplex,flow-control> 1000baseT <full-duplex,hw-loopback>
13
+ fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
14
+ lladdr 00:23:df:ff:fe:7f:55:e4
15
+ media: autoselect <full-duplex> status: inactive
16
+ supported media: autoselect <full-duplex>
17
+ en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
18
+ ether 00:23:6c:8d:c8:cc
19
+ media: autoselect (<unknown type>) status: inactive
20
+ supported media: autoselect
21
+ vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
22
+ inet 192.168.248.1 netmask 0xffffff00 broadcast 192.168.248.255
23
+ ether 00:50:56:c0:00:08
24
+ vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
25
+ inet 172.16.66.1 netmask 0xffffff00 broadcast 172.16.66.255
26
+ ether 00:50:56:c0:00:01
27
+ en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
28
+ inet6 fe80::21c:42ff:fe00:8%en2 prefixlen 64 scopeid 0x9
29
+ inet 10.211.55.2 netmask 0xffffff00 broadcast 10.211.55.255
30
+ ether 00:1c:42:00:00:08
31
+ media: autoselect status: active
32
+ supported media: autoselect
33
+ en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
34
+ inet6 fe80::21c:42ff:fe00:9%en3 prefixlen 64 scopeid 0xa
35
+ inet 10.37.129.2 netmask 0xffffff00 broadcast 10.37.129.255
36
+ ether 00:1c:42:00:00:09
37
+ media: autoselect status: active
38
+ supported media: autoselect
@@ -0,0 +1,58 @@
1
+ br0 Link encap:Ethernet HWaddr 00:1b:fc:2e:ac:a0
2
+ inet addr:192.168.4.10 Bcast:192.168.4.255 Mask:255.255.255.0
3
+ inet6 addr: fe80::21b:fcff:fe2e:aca0/64 Scope:Link
4
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
5
+ RX packets:6200715 errors:0 dropped:0 overruns:0 frame:0
6
+ TX packets:3019659 errors:0 dropped:0 overruns:0 carrier:0
7
+ collisions:0 txqueuelen:0
8
+ RX bytes:7049562204 (7.0 GB) TX bytes:2425295654 (2.4 GB)
9
+
10
+ eth0 Link encap:Ethernet HWaddr 00:04:e2:fb:fa:fc
11
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
12
+ RX packets:0 errors:0 dropped:0 overruns:0 frame:0
13
+ TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
14
+ collisions:0 txqueuelen:1000
15
+ RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
16
+ Interrupt:17
17
+
18
+ eth1 Link encap:Ethernet HWaddr 00:1b:fc:2e:ac:a0
19
+ inet6 addr: fe80::21b:fcff:fe2e:aca0/64 Scope:Link
20
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
21
+ RX packets:6431548 errors:0 dropped:0 overruns:0 frame:0
22
+ TX packets:3178254 errors:0 dropped:0 overruns:0 carrier:0
23
+ collisions:0 txqueuelen:1000
24
+ RX bytes:7314656702 (7.3 GB) TX bytes:2465850613 (2.4 GB)
25
+ Interrupt:17
26
+
27
+ lo Link encap:Local Loopback
28
+ inet addr:127.0.0.1 Mask:255.0.0.0
29
+ inet6 addr: ::1/128 Scope:Host
30
+ UP LOOPBACK RUNNING MTU:16436 Metric:1
31
+ RX packets:32717 errors:0 dropped:0 overruns:0 frame:0
32
+ TX packets:32717 errors:0 dropped:0 overruns:0 carrier:0
33
+ collisions:0 txqueuelen:0
34
+ RX bytes:7176805 (7.1 MB) TX bytes:7176805 (7.1 MB)
35
+
36
+ vmnet1 Link encap:Ethernet HWaddr 7a:67:23:e6:6c:90
37
+ inet addr:172.16.66.1 Bcast:192.168.122.255 Mask:255.255.255.0
38
+ inet6 addr: fe80::7867:23ff:fee6:6c90/64 Scope:Link
39
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
40
+ RX packets:0 errors:0 dropped:0 overruns:0 frame:0
41
+ TX packets:21412 errors:0 dropped:0 overruns:0 carrier:0
42
+ collisions:0 txqueuelen:0
43
+ RX bytes:0 (0.0 B) TX bytes:1435979 (1.4 MB)
44
+
45
+ wlan0 Link encap:Ethernet HWaddr 00:15:af:0d:f6:36
46
+ inet6 addr: fe80::215:afff:fe0d:f636/64 Scope:Link
47
+ UP BROADCAST MULTICAST MTU:1500 Metric:1
48
+ RX packets:12 errors:0 dropped:0 overruns:0 frame:0
49
+ TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
50
+ collisions:0 txqueuelen:1000
51
+ RX bytes:1356 (1.3 KB) TX bytes:2412 (2.4 KB)
52
+
53
+ wmaster0 Link encap:UNSPEC HWaddr 00-15-AF-0D-F6-36-00-00-00-00-00-00-00-00-00-00
54
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
55
+ RX packets:0 errors:0 dropped:0 overruns:0 frame:0
56
+ TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
57
+ collisions:0 txqueuelen:1000
58
+ RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'columbus'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auser-columbus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ari Lerner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: arilerner@mac.com
18
+ executables:
19
+ - columbus
20
+ - columbus-client
21
+ - columbus-server
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - README.rdoc
26
+ - LICENSE
27
+ files:
28
+ - README.rdoc
29
+ - VERSION.yml
30
+ - bin/columbus
31
+ - bin/columbus-client
32
+ - bin/columbus-server
33
+ - lib/columbus
34
+ - lib/columbus/client.rb
35
+ - lib/columbus/server.rb
36
+ - lib/columbus.rb
37
+ - test/columbus_client_test.rb
38
+ - test/columbus_server_test.rb
39
+ - test/fixtures
40
+ - test/fixtures/ifconfig-mac
41
+ - test/fixtures/ifconfig-vmware
42
+ - test/test_helper.rb
43
+ - LICENSE
44
+ has_rdoc: true
45
+ homepage: http://github.com/auser/columbus
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --inline-source
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: TODO
71
+ test_files: []
72
+