grs-search 1.0.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a4de9986aecb5baab9c00a9c50c585e9631271c
4
+ data.tar.gz: 24c38ebc5aaac85d18eecc058bc6ea6ce0f428ff
5
+ SHA512:
6
+ metadata.gz: 4c6503cca673e497f56b2fa82d66a54da8bff2aec64d391b6f402ba70a3d8a0495cb028335aa2962eb226c55bdf7abf9338c662319c60bf69c31ae0c00f328f3
7
+ data.tar.gz: 1a01604738eb772c9c3ec4429ee75da644517e9eaf76281c7d28ea586bf0ec28d2f68c1796ed01774f29da701f2d763b973ba8906121d7c135e69b7d0f8aa37e
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rest-client', '~>1.7.0'
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "rspec", '~>3.1.0'
9
+ gem "yard"
10
+ gem "bundler"
11
+ gem "jeweler"
12
+ gem "simplecov"
13
+ end
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2015 Tobias Begalke
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL TOBIAS BEGALKE BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,56 @@
1
+ grs-search
2
+ ==========
3
+
4
+ A Ruby library to query the RIPE GRS API (http://rest.db.ripe.net/search).
5
+ With grs-search you can lookup information regarding the network an IP address
6
+ belongs to.
7
+
8
+ Usage
9
+ -----
10
+
11
+ ```ruby
12
+ require 'grs-search'
13
+
14
+ net = GRSSearch.lookup('66.249.64.121')
15
+
16
+ net.source
17
+ > "ARIN-GRS"
18
+
19
+ net.ip_from
20
+ > "66.249.64.0"
21
+
22
+ net.ip_to
23
+ > "66.249.95.255"
24
+
25
+ net.ip_from.to_i
26
+ > 1123631104
27
+
28
+ net.ip_to.to_i
29
+ > 1123639295
30
+
31
+ net.org
32
+ > 'GOGL'
33
+
34
+ net.net_name
35
+ > 'GOOGLE'
36
+
37
+ net.net_description
38
+ > 'DUMMY DESCRIPTION"
39
+
40
+ net.status
41
+ > 'allocation'
42
+
43
+ net.country
44
+ > 'FR'
45
+
46
+ net.net_cidr
47
+ > '66.249.64.0/24'
48
+
49
+ ```
50
+
51
+ Contribute
52
+ ----------
53
+
54
+ Feel free to fork this repository and send me pull requests if you add
55
+ functionality.
56
+
@@ -0,0 +1,43 @@
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://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "grs-search"
18
+ gem.homepage = "http://github.com/elcamino/grs-search"
19
+ gem.license = "BSD"
20
+ gem.summary = %Q{Look up GRS data via the RIPE API}
21
+ gem.description = %Q{This Ruby library looks up GRS data via the Ripe API (http://rest.db.ripe.net)}
22
+ gem.email = "tob@spyz.org"
23
+ gem.authors = ["Tobias Begalke"]
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
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,67 @@
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
+ # stub: grs-search 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "grs-search"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Tobias Begalke"]
14
+ s.date = "2015-01-27"
15
+ s.description = "This Ruby library looks up GRS data via the Ripe API (http://rest.db.ripe.net)"
16
+ s.email = "tob@spyz.org"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "grs-search.gemspec",
30
+ "lib/grs-search.rb",
31
+ "lib/grs-search/response.rb",
32
+ "spec/grs-search_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/elcamino/grs-search"
36
+ s.licenses = ["BSD"]
37
+ s.rubygems_version = "2.2.2"
38
+ s.summary = "Look up GRS data via the RIPE API"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<rest-client>, ["~> 1.7.0"])
45
+ s.add_development_dependency(%q<rspec>, ["~> 3.1.0"])
46
+ s.add_development_dependency(%q<yard>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, [">= 0"])
48
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
49
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rest-client>, ["~> 1.7.0"])
52
+ s.add_dependency(%q<rspec>, ["~> 3.1.0"])
53
+ s.add_dependency(%q<yard>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, [">= 0"])
55
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_dependency(%q<simplecov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rest-client>, ["~> 1.7.0"])
60
+ s.add_dependency(%q<rspec>, ["~> 3.1.0"])
61
+ s.add_dependency(%q<yard>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, [">= 0"])
64
+ s.add_dependency(%q<simplecov>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,40 @@
1
+ require 'rest-client'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'grs-search/response'
5
+ require 'pp'
6
+
7
+ class GRSSearch
8
+ RIPE_API_URI = URI.parse('http://rest.db.ripe.net/search.json')
9
+ GRS_SOURCES = %w(ripe-grs arin-grs apnic-grs lacnic-grs afrinic-grs radb-grs)
10
+
11
+ class << self
12
+ attr_accessor :proxy_url
13
+ end
14
+
15
+ def self.lookup(ip)
16
+ url = RIPE_API_URI.merge("?query-string=#{ip}&" + GRS_SOURCES.map { |s| 'source=' + s }.join('&'))
17
+
18
+ if self.proxy_url
19
+ _rest_client_proxy = RestClient.proxy
20
+ RestClient.proxy = self.proxy_url
21
+ end
22
+
23
+ response = nil
24
+
25
+ begin
26
+ res = RestClient.get(url.to_s)
27
+ data = JSON.parse(res)
28
+ response = Response.new(data)
29
+ rescue Exception => e
30
+ STDERR.puts e.to_s
31
+ STDERR.puts e.backtrace.join("\n")
32
+ end
33
+
34
+ if self.proxy_url
35
+ RestClient.proxy = _rest_client_proxy
36
+ end
37
+
38
+ response
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ require 'ipaddr'
2
+
3
+ class GRSSearch
4
+ class Response
5
+ attr_reader :source, :ip_from, :ip_to, :name, :description,
6
+ :country, :status, :cidr, :org
7
+
8
+
9
+ def initialize(json_data)
10
+ json_data['objects']['object'].find_all { |data| data['type'] == 'inetnum' }.each do |i|
11
+ @source ||= i['source']['id']
12
+
13
+ # IP address range
14
+ #
15
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'inetnum' }
16
+ _ip_from, _ip_to = item['value'].split(/\s+-\s+/).map { |ip| ip.strip }
17
+ @ip_from ||= IPAddr.new _ip_from
18
+ @ip_to ||= IPAddr.new _ip_to
19
+ end
20
+
21
+ # net name
22
+ #
23
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'netname' }
24
+ @name ||= item['value']
25
+ end
26
+
27
+ # net description
28
+ #
29
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'descr' }
30
+ @description ||= item['value']
31
+ end
32
+
33
+ # country
34
+ #
35
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'country' }
36
+ @country ||= item['value']
37
+ end
38
+
39
+ # status
40
+ #
41
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'status' }
42
+ @status ||= item['value']
43
+ end
44
+
45
+ # organization
46
+ #
47
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'org' }
48
+ @org ||= item['value']
49
+ end
50
+
51
+ end
52
+
53
+ json_data['objects']['object'].find_all { |data| data['type'] == 'route' }.each do |i|
54
+
55
+ # network CIDR notation
56
+ #
57
+ if item = i['attributes']['attribute'].detect { |a| a['name'] == 'route' }
58
+ @cidr = item['value']
59
+ end
60
+ end
61
+
62
+ def inspect
63
+ "GRSSearch::Response\##{self.object_id} - source:#{source} ip_from:#{ip_from} ip_to:#{ip_to} name:#{name} description:#{description} country:#{country} status:#{status} cidr:#{cidr} org:#{org}"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe GRSSearch do
4
+ let(:res_afrinic) { GRSSearch.lookup('41.206.1.10') }
5
+ let(:res_google) { GRSSearch.lookup('66.249.64.0') }
6
+ let(:res_kabel) { GRSSearch.lookup('178.27.236.214') }
7
+
8
+ it "is able to fetch data from the API endpoint" do
9
+ expect(res_google.class).to eq GRSSearch::Response
10
+ expect(res_google.source).to eq 'arin-grs'
11
+ expect(res_google.ip_from).to eq '66.249.64.0'
12
+ expect(res_google.ip_to).to eq '66.249.95.255'
13
+ expect(res_google.ip_from.to_i).to eq 1123631104
14
+ expect(res_google.ip_to.to_i).to eq 1123639295
15
+ expect(res_google.org).to eq 'GOGL'
16
+ expect(res_google.name).to eq 'GOOGLE'
17
+ expect(res_google.description).not_to be
18
+ expect(res_google.status).to eq 'allocation'
19
+ expect(res_google.country).not_to be
20
+ expect(res_google.cidr).to eq '66.249.64.0/24'
21
+
22
+ expect(res_afrinic.class).to eq GRSSearch::Response
23
+ expect(res_afrinic.source).to eq 'afrinic-grs'
24
+ expect(res_afrinic.ip_from).to eq '41.206.1.0'
25
+ expect(res_afrinic.ip_to).to eq '41.206.1.255'
26
+ expect(res_afrinic.ip_from.to_i).to eq 701366528
27
+ expect(res_afrinic.ip_to.to_i).to eq 701366783
28
+ expect(res_afrinic.org).not_to be
29
+ expect(res_afrinic.name).to eq 'MTNNG-0007-MTNCORP-LAGREGION-WIMAX'
30
+ expect(res_afrinic.status).to eq 'ASSIGNED PA'
31
+ expect(res_afrinic.country).to eq 'NG'
32
+ expect(res_afrinic.cidr).to eq '41.206.0.0/19'
33
+
34
+ expect(res_kabel.class).to eq GRSSearch::Response
35
+ expect(res_kabel.source).to eq 'ripe-grs'
36
+ expect(res_kabel.ip_from).to eq '178.26.0.0'
37
+ expect(res_kabel.ip_to).to eq '178.27.255.255'
38
+ expect(res_kabel.ip_from.to_i).to eq 2988048384
39
+ expect(res_kabel.ip_to.to_i).to eq 2988179455
40
+ expect(res_kabel.org).not_to be
41
+ expect(res_kabel.name).to eq 'KABEL-DEUTSCHLAND-CUSTOMER-SERVICES-23'
42
+ expect(res_kabel.status).to eq 'ASSIGNED PA'
43
+ expect(res_kabel.country).to eq 'DE'
44
+ expect(res_kabel.cidr).to eq '178.27.128.0/17'
45
+
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+
4
+ module SimpleCov::Configuration
5
+ def clean_filters
6
+ @filters = []
7
+ end
8
+ end
9
+
10
+ SimpleCov.configure do
11
+ clean_filters
12
+ load_adapter 'test_frameworks'
13
+ end
14
+
15
+ ENV["COVERAGE"] && SimpleCov.start do
16
+ add_filter "/.rvm/"
17
+ end
18
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
19
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
20
+
21
+ require 'rspec'
22
+ require 'grs-search'
23
+
24
+ # Requires supporting files with custom matchers and macros, etc,
25
+ # in ./support/ and its subdirectories.
26
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
27
+
28
+ RSpec.configure do |config|
29
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grs-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Begalke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This Ruby library looks up GRS data via the Ripe API (http://rest.db.ripe.net)
98
+ email: tob@spyz.org
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.md
104
+ files:
105
+ - ".document"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - VERSION
112
+ - grs-search.gemspec
113
+ - lib/grs-search.rb
114
+ - lib/grs-search/response.rb
115
+ - spec/grs-search_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: http://github.com/elcamino/grs-search
118
+ licenses:
119
+ - BSD
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Look up GRS data via the RIPE API
141
+ test_files: []