ether_ping 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>ether_ping</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'ethernet', '>= 0.1.0'
4
+
5
+ group :development do
6
+ gem 'rdoc', '>= 3.6.1'
7
+ gem 'rspec', '~> 2.6.0'
8
+ gem 'bundler', '~> 1.0.0'
9
+ gem 'jeweler', '~> 1.6.0'
10
+ gem 'rcov', '>= 0'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ ethernet (0.1.1)
6
+ system-getifaddrs (~> 0.1.1)
7
+ git (1.2.5)
8
+ jeweler (1.6.0)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.9.0)
13
+ rcov (0.9.9)
14
+ rdoc (3.6.1)
15
+ rspec (2.6.0)
16
+ rspec-core (~> 2.6.0)
17
+ rspec-expectations (~> 2.6.0)
18
+ rspec-mocks (~> 2.6.0)
19
+ rspec-core (2.6.3)
20
+ rspec-expectations (2.6.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.6.0)
23
+ system-getifaddrs (0.1.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ ethernet (>= 0.1.0)
31
+ jeweler (~> 1.6.0)
32
+ rcov
33
+ rdoc (>= 3.6.1)
34
+ rspec (~> 2.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Victor Costan
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,39 @@
1
+ = ether_ping
2
+
3
+ Command-line tool providing a ping equivalent for Ethernet frames.
4
+
5
+ == Usage
6
+
7
+ While ping uses an echo service embedded in every TCP/IP stack, ether_ping
8
+ relies on a server program to have its frames echoed. First start the server on
9
+ the destination computer, and tell it what Ethernet device it should listen to.
10
+
11
+ ether_ping_server eth0 # on Linux
12
+ ether_ping_server en0 # on Mac OS
13
+
14
+ Then launch the ping utility. It wants to know the following information:
15
+ * the Ethernet device that will be used for sending ping frames
16
+ * the MAC of the destination's Ethernet device
17
+ * the data to be sent
18
+
19
+ ether_ping eth0 c42c0337fffc aabbccdd
20
+
21
+
22
+ == Contributing to ether_ping
23
+
24
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
25
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
26
+ * Fork the project
27
+ * Start a feature/bugfix branch
28
+ * Commit and push until you are happy with your contribution
29
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
30
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
31
+
32
+ == Author
33
+
34
+ Victor Costan victor@costan.us
35
+
36
+ == Copyright
37
+
38
+ Copyright (c) 2011 Massachusetts Institute of Technology.
39
+ See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ether_ping"
18
+ gem.homepage = "http://github.com/pwnall/ether_ping"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Command-line ping equivalent for Ethernet frames.}
21
+ gem.description = %Q{Contains an Ethernet-level ping server and client.}
22
+ gem.email = "victor@costan.us"
23
+ gem.authors = ["Victor Costan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "ether_ping #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/ether_ping ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ether_ping'
4
+
5
+ if ARGV.length < 3
6
+ print <<END_USAGE
7
+ Usage: #{$0} net_interface dest_mac [ether_type] data
8
+ net_interface: name of the Ethernet interface, e.g. eth0
9
+ ether_type: packet type for the Ethernet II frame, in hex (2 bytes)
10
+ dest_mac: destination MAC for the ping packets, in hex (6 bytes)
11
+ data: ping packet data, in hex (0-padded to 64 bytes)
12
+
13
+ Available Ethernet interfaces:
14
+ #{Ethernet.devices.keys.sort.join("\n")}
15
+ END_USAGE
16
+ exit 1
17
+ end
18
+
19
+ interface = ARGV[0]
20
+ dest_mac = ARGV[1]
21
+ if ARGV.length == 3
22
+ ether_type_string = '88B5'
23
+ data = [ARGV[2]].pack('H*')
24
+ else
25
+ ether_type_string = ARGV[2]
26
+ data = [ARGV[3]].pack('H*')
27
+ end
28
+ ether_type = [ether_type_string].pack('H*').unpack('n').first
29
+
30
+ client = EtherPing::Client.new interface, ether_type, dest_mac
31
+
32
+ loop do
33
+ print "Pinging #{dest_mac}... "
34
+ STDOUT.flush
35
+ puts client.ping(data) ? "OK" : "Failed"
36
+ STDOUT.flush
37
+ sleep 1
38
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ether_ping'
4
+
5
+ if ARGV.length < 1
6
+ print <<END_USAGE
7
+ Usage: #{$0} net_interface [ether_type]
8
+ net_interface: name of the Ethernet interface, e.g. eth0
9
+ ether_type: packet type for the Ethernet II frame, in hex (2 bytes)
10
+ the default is 88B5, intended for research and experiments
11
+
12
+ Available Ethernet interfaces:
13
+ #{Ethernet.devices.keys.sort.join("\n")}
14
+ END_USAGE
15
+ exit 1
16
+ end
17
+
18
+ interface = ARGV[0]
19
+ ether_type = [ARGV[1] || '88B5'].pack('H*').unpack('n').first
20
+
21
+ ping_server = EtherPing::Server.new interface, ether_type
22
+ ping_server.run
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ether_ping}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Victor Costan}]
12
+ s.date = %q{2011-05-27}
13
+ s.description = %q{Contains an Ethernet-level ping server and client.}
14
+ s.email = %q{victor@costan.us}
15
+ s.executables = [%q{ether_ping_server}, %q{ether_ping}]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".project",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/ether_ping",
31
+ "bin/ether_ping_server",
32
+ "ether_ping.gemspec",
33
+ "lib/ether_ping.rb",
34
+ "lib/ether_ping/client.rb",
35
+ "lib/ether_ping/server.rb",
36
+ "spec/ether_ping_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/pwnall/ether_ping}
40
+ s.licenses = [%q{MIT}]
41
+ s.require_paths = [%q{lib}]
42
+ s.rubygems_version = %q{1.8.4}
43
+ s.summary = %q{Command-line ping equivalent for Ethernet frames.}
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<ethernet>, [">= 0.1.0"])
50
+ s.add_development_dependency(%q<rdoc>, [">= 3.6.1"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<ethernet>, [">= 0.1.0"])
57
+ s.add_dependency(%q<rdoc>, [">= 3.6.1"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<ethernet>, [">= 0.1.0"])
65
+ s.add_dependency(%q<rdoc>, [">= 3.6.1"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,37 @@
1
+ require 'ethernet'
2
+
3
+ # :nodoc: namespace
4
+ module EtherPing
5
+
6
+ # ether_ping implementation.
7
+ class Client
8
+ def initialize(eth_device, ether_type, destination_mac)
9
+ @socket = Ethernet.raw_socket eth_device, ether_type
10
+ @source_mac = Ethernet::Devices.mac eth_device
11
+ @dest_mac = [destination_mac].pack('H*')[0, 6]
12
+ @ether_type = [ether_type].pack('n')
13
+ end
14
+
15
+ attr_reader :socket
16
+ attr_reader :source_mac
17
+ attr_reader :dest_mac
18
+
19
+ # Pings over raw Ethernet sockets.
20
+ #
21
+ # Returns true if the ping receives a response, false otherwise.
22
+ def ping(data, timeout = 1)
23
+ data = data.clone
24
+ # Pad data to have at least 64 bytes.
25
+ data += "\0" * (64 - data.length) if data.length < 64
26
+
27
+ ping_packet = @dest_mac + @source_mac + @ether_type + data
28
+ @socket.send ping_packet, 0
29
+
30
+ response_packet = @source_mac + @dest_mac + @ether_type + data
31
+ response = @socket.recv response_packet.length * 2
32
+
33
+ response == response_packet
34
+ end
35
+ end # module EtherPing::Client
36
+
37
+ end # namespace EtherPing
@@ -0,0 +1,48 @@
1
+ require 'ethernet'
2
+
3
+ # :nodoc: namespace
4
+ module EtherPing
5
+
6
+ # Responder for ping utility using raw Ethernet sockets.
7
+ class Server
8
+ module Connection
9
+ def receive_data(packet)
10
+ source_mac = packet[0, 6].unpack('H*')
11
+ dest_mac = packet[6, 6].unpack('H*')
12
+ ether_type = packet[12, 2].unpack('H*')
13
+
14
+ puts "Src: #{source_mac} Dst: #{dest_mac} Eth: #{ether_type}\n"
15
+ puts packet[14..-1].unpack('H*')
16
+
17
+ # Exchange the source and destination ARP addresses.
18
+ packet[0, 6], packet[6, 6] = packet[6, 6], packet[0, 6]
19
+ send_data packet
20
+ end
21
+ end
22
+
23
+ class ConnectionWrapper
24
+ include Connection
25
+
26
+ def initialize(socket)
27
+ @socket = socket
28
+ end
29
+
30
+ def send_data(data)
31
+ @socket.send data, 0
32
+ end
33
+ end
34
+
35
+ def run
36
+ connection = ConnectionWrapper.new @socket
37
+ loop do
38
+ packet = @socket.recv 65536
39
+ connection.receive_data packet
40
+ end
41
+ end
42
+
43
+ def initialize(eth_device, ether_type)
44
+ @socket = Ethernet.raw_socket eth_device, ether_type
45
+ end
46
+ end # module EtherPing::Server
47
+
48
+ end # namespace EtherPing
data/lib/ether_ping.rb ADDED
@@ -0,0 +1,6 @@
1
+ # Documentation here.
2
+ module EtherPing
3
+ end
4
+
5
+ require 'ether_ping/client.rb'
6
+ require 'ether_ping/server.rb'
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "EtherPing" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ether_ping'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ether_ping
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Victor Costan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 27
28
+ segments:
29
+ - 0
30
+ - 1
31
+ - 0
32
+ version: 0.1.0
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ name: ethernet
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 29
44
+ segments:
45
+ - 3
46
+ - 6
47
+ - 1
48
+ version: 3.6.1
49
+ prerelease: false
50
+ version_requirements: *id002
51
+ name: rdoc
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 2
62
+ - 6
63
+ - 0
64
+ version: 2.6.0
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ name: rspec
68
+ - !ruby/object:Gem::Dependency
69
+ type: :development
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 23
76
+ segments:
77
+ - 1
78
+ - 0
79
+ - 0
80
+ version: 1.0.0
81
+ prerelease: false
82
+ version_requirements: *id004
83
+ name: bundler
84
+ - !ruby/object:Gem::Dependency
85
+ type: :development
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 15
92
+ segments:
93
+ - 1
94
+ - 6
95
+ - 0
96
+ version: 1.6.0
97
+ prerelease: false
98
+ version_requirements: *id005
99
+ name: jeweler
100
+ - !ruby/object:Gem::Dependency
101
+ type: :development
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ prerelease: false
112
+ version_requirements: *id006
113
+ name: rcov
114
+ description: Contains an Ethernet-level ping server and client.
115
+ email: victor@costan.us
116
+ executables:
117
+ - ether_ping_server
118
+ - ether_ping
119
+ extensions: []
120
+
121
+ extra_rdoc_files:
122
+ - LICENSE.txt
123
+ - README.rdoc
124
+ files:
125
+ - .document
126
+ - .project
127
+ - .rspec
128
+ - Gemfile
129
+ - Gemfile.lock
130
+ - LICENSE.txt
131
+ - README.rdoc
132
+ - Rakefile
133
+ - VERSION
134
+ - bin/ether_ping
135
+ - bin/ether_ping_server
136
+ - ether_ping.gemspec
137
+ - lib/ether_ping.rb
138
+ - lib/ether_ping/client.rb
139
+ - lib/ether_ping/server.rb
140
+ - spec/ether_ping_spec.rb
141
+ - spec/spec_helper.rb
142
+ homepage: http://github.com/pwnall/ether_ping
143
+ licenses:
144
+ - MIT
145
+ post_install_message:
146
+ rdoc_options: []
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirements: []
169
+
170
+ rubyforge_project:
171
+ rubygems_version: 1.8.4
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: Command-line ping equivalent for Ethernet frames.
175
+ test_files: []
176
+