rtrace 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rtrace.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christoph
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Rtrace
2
+
3
+ Traceroute subset with geocoding using the geocoder gem. Tested on OSX only.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rtrace'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rtrace
18
+
19
+ ## Usage
20
+
21
+ Just do rtrace -h
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rtrace'
4
+ require 'optparse'
5
+
6
+
7
+ options = {}
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "Usage: trace [options] hostname"
10
+
11
+ opts.on("-w", "--wait [seconds]", Float, "Timeout in seconds. Default: 5") do |v|
12
+ options[:timeout] = v
13
+ end
14
+ opts.on("-f", "--first-ttl [ttl]", Integer, "TTL of first packet snet. Default: 1") do |v|
15
+ options[:first_ttl] = v
16
+ end
17
+ opts.on("-m", "--max-ttl [ttl]", Integer, "Max TTL. Default: 30") do |v|
18
+ options[:max_ttl] = v
19
+ end
20
+ end.parse!
21
+ options[:host] = ARGV.last
22
+ if options[:host].nil?
23
+ puts "Need hostname. See rtrace -h for options"
24
+ exit(1)
25
+ end
26
+ options[:timeout] ||= 5;
27
+ options[:max_ttl] ||= 30;
28
+ options[:first_ttl] ||= 1;
29
+
30
+
31
+ Rtrace.trace(options)
32
+
@@ -0,0 +1,97 @@
1
+ require "rtrace/version"
2
+ require 'socket'
3
+ require 'rubygems'
4
+ require 'geocoder'
5
+ require 'timeout'
6
+
7
+
8
+ byebye = proc {
9
+ puts "\x8\x8"+"Canceled. "
10
+ exit(0)
11
+ }
12
+
13
+ trap('INT', byebye)
14
+
15
+ module Rtrace
16
+
17
+
18
+ class << self
19
+ end
20
+
21
+ def self.trace(options)
22
+ @options = options
23
+ port = 33434
24
+
25
+ @send_socket = Socket.new(:INET, :DGRAM)
26
+ @dest_addr = Socket.sockaddr_in(port, options[:host])
27
+ @dest_ip = IPSocket::getaddress(options[:host])
28
+ puts "Traceroute for \"#{options[:host]}\" ( #{@dest_ip} ) ..."
29
+ puts
30
+
31
+ begin
32
+ @recv_socket = Socket.new( Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_ICMP)
33
+ rescue Errno::EPERM => e
34
+ puts "Sorry, you need to be root. Raw packets and all. Let me know if there's a better way."
35
+ exit(1)
36
+ end
37
+ @recv_addr = Socket.sockaddr_in(port, "")
38
+ @recv_socket.bind(@recv_addr)
39
+ self.run_loop
40
+ end
41
+
42
+ def self.run_loop
43
+ ttl = @options[:first_ttl]
44
+ while true do
45
+ break if ttl>@options[:max_ttl]
46
+ @send_socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [ttl].pack('i'))
47
+ t1 = Time.now
48
+ @send_socket.send("", 0, @dest_addr)
49
+
50
+
51
+
52
+
53
+ data = ""
54
+ begin
55
+ timeout(@options[:timeout]) do
56
+ data = @recv_socket.recvfrom( 512 )[1]
57
+ end
58
+ rescue Timeout::Error
59
+ puts ttl.to_s.ljust(5)+"*"
60
+ ttl += 1
61
+ next
62
+ end
63
+
64
+
65
+
66
+
67
+ time = ((Time.now - t1)*1000).round 1
68
+ time = time.to_s+" ms"
69
+ ip = data.ip_address
70
+ loc = Geocoder.search(ip).first
71
+
72
+ if loc.city.empty?
73
+ place = ""
74
+ else
75
+ place = "#{loc.city}, #{loc.state}"
76
+ end
77
+
78
+ begin
79
+ name = Socket.getaddrinfo(ip, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME, true)[0][2]
80
+ rescue
81
+ name = ""
82
+ end
83
+
84
+ s_ttl = ttl.to_s.ljust(5)
85
+ name = name.ljust(45)
86
+ s_ip = ip.ljust(20)
87
+ time = time.ljust(15)
88
+ place = place.ljust(25)
89
+
90
+ puts s_ttl+name+s_ip+time+place
91
+
92
+ ttl += 1
93
+ break if @dest_ip==ip
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module Rtrace
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rtrace/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Christoph Koehler"]
6
+ gem.email = ["christoph@zerodeviation.net"]
7
+ gem.description = %q{Subset of traceroute functionality with added geocoded
8
+ location based on IP. Uses the geocoder gem. Only tested on OSX.}
9
+ gem.summary = %q{traceroute in Ruby with geocoding. Tested on OSX only.}
10
+ gem.homepage = %q{http://rubygems.org/gems/rtrace}
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "rtrace"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Rtrace::VERSION
18
+
19
+ gem.add_dependency 'geocoder'
20
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christoph Koehler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geocoder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! "Subset of traceroute functionality with added geocoded\n location
31
+ based on IP. Uses the geocoder gem. Only tested on OSX."
32
+ email:
33
+ - christoph@zerodeviation.net
34
+ executables:
35
+ - rtrace
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - bin/rtrace
45
+ - lib/rtrace.rb
46
+ - lib/rtrace/version.rb
47
+ - rtrace.gemspec
48
+ homepage: http://rubygems.org/gems/rtrace
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: traceroute in Ruby with geocoding. Tested on OSX only.
72
+ test_files: []