poweron 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ begin
2
+ require 'rake/gempackagetask'
3
+ rescue LoadError
4
+ end
5
+ require 'rake/clean'
6
+ require 'rbconfig'
7
+ include Config
8
+
9
+ PKG_NAME = 'poweron'
10
+ PKG_VERSION = File.read('VERSION').chomp
11
+ PKG_FILES = FileList['**/*'].exclude(/^(doc|pkg|coverage)/)
12
+ CLEAN.include 'coverage', 'doc'
13
+
14
+ if defined? Gem
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = PKG_NAME
17
+ s.version = PKG_VERSION
18
+ s.summary = "Library to poweron sleeping computers."
19
+ s.description = "Library to send a wake-on-lan packet in order to poweron a sleeing computer."
20
+ s.author = "Florian Frank"
21
+ s.email = "flori@ping.de"
22
+ s.homepage = "http://flori.github.com/#{PKG_NAME}"
23
+ s.files = PKG_FILES
24
+ s.require_path = 'lib'
25
+ s.executables << "poweron"
26
+ end
27
+
28
+ task :gemspec do
29
+ File.open('poweron.gemspec', 'w') do |output|
30
+ output.write spec.to_ruby
31
+ end
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.need_tar = true
36
+ pkg.package_files += PKG_FILES
37
+ end
38
+ end
39
+
40
+ desc m = "Writing version information for #{PKG_VERSION}"
41
+ task :version do
42
+ puts m
43
+ File.open(File.join('lib', PKG_NAME, 'version.rb'), 'w') do |v|
44
+ v.puts <<EOT
45
+ module Poweron
46
+ # Poweron version
47
+ VERSION = '#{PKG_VERSION}'
48
+ VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
49
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
50
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
51
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
52
+ end
53
+ EOT
54
+ end
55
+ end
56
+
57
+ task :default => [ :version ]
58
+
59
+ task :release => [ :clobber, :version, :gemspec, :package ]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'poweron'
4
+
5
+ interface = ARGV.shift or fail 'need a mac address/hostname/ip address as first argument'
6
+ Poweron.poweron(interface)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'poweron/version'
4
+ require 'socket'
5
+ require 'ipaddr'
6
+
7
+ module Poweron
8
+ module_function
9
+
10
+ def poweron(interface, opts = {})
11
+ mac =
12
+ if interface =~ /\A[0-9a-f]{2}(:[0-9a-f]{2}){5}\Z/i
13
+ interface
14
+ elsif File.readable?('/etc/ethers')
15
+ File.open('/etc/ethers') do |ethers|
16
+ ethers.find { |line| line =~ /^(\S+)\s+#{interface}/ and break $1 }
17
+ end
18
+ end
19
+ mac or raise ArgumentError, "interface #{interface.inspect} could not be resolved"
20
+ mac = mac.split(/:/).map { |x| x.to_i(16) }
21
+ mac.size == 6 and mac.all? { |x| (0..0xff) === x } or
22
+ raise ArgumentError, "mac address has to be 6 bytes long"
23
+ port = opts[:port] || 9
24
+ (0..0xffff) === port or raise ArgumentError, "port in invalid range"
25
+ ip = opts[:ip] || '255.255.255.255'
26
+ ip = IPAddr === ip ? ip : IPAddr.new(ip)
27
+ data = [ 0xff ] * 6 + mac * 16
28
+ udp = UDPSocket.new
29
+ udp.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1
30
+ udp.connect ip.to_s, port
31
+ udp.send data.pack('c*'), 0
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Poweron
2
+ # Poweron version
3
+ VERSION = '0.0.0'
4
+ VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{poweron}
5
+ s.version = "0.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Florian Frank"]
9
+ s.date = %q{2011-05-07}
10
+ s.description = %q{Library to send a wake-on-lan packet in order to poweron a sleeing computer.}
11
+ s.email = %q{flori@ping.de}
12
+ s.executables = ["poweron"]
13
+ s.files = ["poweron.gemspec", "Rakefile", "lib", "lib/poweron", "lib/poweron/version.rb", "lib/poweron.rb", "bin", "bin/poweron", "VERSION"]
14
+ s.homepage = %q{http://flori.github.com/poweron}
15
+ s.require_paths = ["lib"]
16
+ s.rubygems_version = %q{1.7.1}
17
+ s.summary = %q{Library to poweron sleeping computers.}
18
+
19
+ if s.respond_to? :specification_version then
20
+ s.specification_version = 3
21
+
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
+ else
24
+ end
25
+ else
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poweron
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Florian Frank
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-07 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Library to send a wake-on-lan packet in order to poweron a sleeing computer.
22
+ email: flori@ping.de
23
+ executables:
24
+ - poweron
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - poweron.gemspec
31
+ - Rakefile
32
+ - lib/poweron/version.rb
33
+ - lib/poweron.rb
34
+ - bin/poweron
35
+ - VERSION
36
+ homepage: http://flori.github.com/poweron
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.7.1
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Library to poweron sleeping computers.
69
+ test_files: []
70
+