wol 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/wol +1 -1
- data/lib/parsefile.rb +7 -0
- data/lib/wol.rb +1 -1
- data/spec/hosts.wol +24 -0
- data/spec/parsefile_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/wol_spec.rb +4 -0
- metadata +4 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/bin/wol
CHANGED
data/lib/parsefile.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# Parse a text file containing hardware addresses, host names/addresses, and port numbers
|
1
2
|
class ParseFile
|
2
3
|
|
4
|
+
# Parse a given text file and return a hash containing the results
|
3
5
|
def self.parse(file)
|
4
6
|
hosts = []
|
5
7
|
if File.exist?(file) && File.readable?(file)
|
@@ -22,14 +24,19 @@ class ParseFile
|
|
22
24
|
return hosts
|
23
25
|
end
|
24
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
# Check if a given hardware address is correctly formed.
|
25
30
|
def self.check_mac(mac)
|
26
31
|
/^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/.match(mac)
|
27
32
|
end
|
28
33
|
|
34
|
+
# Check that a host/ip address doesn't contain any illegal characters.
|
29
35
|
def self.check_host(host)
|
30
36
|
/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$)|(^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$)/.match(host)
|
31
37
|
end
|
32
38
|
|
39
|
+
# Make sure that a given port number is an integer in the correct range (1..61000).
|
33
40
|
def self.sanitize_port(port)
|
34
41
|
p = port.to_i
|
35
42
|
return (1..61000).include?(p) ? p : 9
|
data/lib/wol.rb
CHANGED
data/spec/hosts.wol
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# File structure
|
2
|
+
# --------------
|
3
|
+
# - blank lines are ignored
|
4
|
+
# - comment lines are ignored (lines starting with a hash mark '#')
|
5
|
+
# - other lines are considered valid records and can have 3 columns:
|
6
|
+
#
|
7
|
+
# Hardware address, IP address, destination port
|
8
|
+
#
|
9
|
+
# the last two are optional, in which case the following defaults
|
10
|
+
# are used:
|
11
|
+
#
|
12
|
+
# IP address: 255.255.255.255 (the limited broadcast address)
|
13
|
+
# port: 9 (the discard port)
|
14
|
+
#
|
15
|
+
|
16
|
+
01:02:03:04:05:06 192.168.1.255 9
|
17
|
+
01:02:03:04:05:06 192.168.2.230 12
|
18
|
+
07:09:09:0A:0B:0C example.com
|
19
|
+
0D:0E:0F:00:10:11
|
20
|
+
|
21
|
+
# Invalid entries
|
22
|
+
FF:FF:aa
|
23
|
+
0D:0E:0F:00:10:11 ;
|
24
|
+
07:09:09:0A:0B:0C 192.168.1.254 a
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "ParseFile" do
|
4
|
+
it "be able to parse a test file correctly" do
|
5
|
+
expected = [{:port=>9, :mac=>"01:02:03:04:05:06", :address=>"192.168.1.255"},
|
6
|
+
{:port=>12, :mac=>"01:02:03:04:05:06", :address=>"192.168.2.230"},
|
7
|
+
{:port=>9, :mac=>"07:09:09:0A:0B:0C", :address=>"example.com"},
|
8
|
+
{:port=>9, :mac=>"07:09:09:0A:0B:0C", :address=>"192.168.1.254"}]
|
9
|
+
|
10
|
+
ParseFile.parse(File.expand_path(File.dirname(__FILE__) + '/hosts.wol')).should == expected
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/wol_spec.rb
CHANGED
@@ -21,6 +21,10 @@ describe "Wake-On-LAN" do
|
|
21
21
|
Wol.new(:macs => "00:08:a1:a9:58:f6", :address => "example.com", :port => 80).wake.should == "Sending magic packet to example.com:80 with 00:08:a1:a9:58:f6\n"
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should send MagicPackets to several hardware addresses at once" do
|
25
|
+
Wol.new(:macs => ["ff:ff:ff:ff:ff:cc", "ff:ff:ff:ff:cc:cc", "ff:ff:ff:ccf:cc:cc"]).wake.should == "Sending magic packet to 255.255.255.255:9 with ff:ff:ff:ff:ff:cc\nSending magic packet to 255.255.255.255:9 with ff:ff:ff:ff:cc:cc\nSending magic packet to 255.255.255.255:9 with ff:ff:ff:ccf:cc:cc\n"
|
26
|
+
end
|
27
|
+
|
24
28
|
it "should return nil if quiet is set to true" do
|
25
29
|
Wol.new(:quiet => true).wake.should == nil
|
26
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Korhonen
|
@@ -42,6 +42,8 @@ files:
|
|
42
42
|
- bin/wol
|
43
43
|
- lib/parsefile.rb
|
44
44
|
- lib/wol.rb
|
45
|
+
- spec/hosts.wol
|
46
|
+
- spec/parsefile_spec.rb
|
45
47
|
- spec/spec.opts
|
46
48
|
- spec/spec_helper.rb
|
47
49
|
- spec/wol_spec.rb
|
@@ -78,5 +80,6 @@ summary: Ruby WoL
|
|
78
80
|
test_files:
|
79
81
|
- spec/spec_helper.rb
|
80
82
|
- spec/wol_spec.rb
|
83
|
+
- spec/parsefile_spec.rb
|
81
84
|
- test/test_wol.rb
|
82
85
|
- test/helper.rb
|