dnsdb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 873be9c9e9a067aafb03f5544b316bfdf71fba6350e568709de7a647465ced40
4
+ data.tar.gz: 16f2c64868452b7fdd8a50d9293a1a84a44b846013cb8233e62304dabd23688f
5
+ SHA512:
6
+ metadata.gz: 55646b04aabbfb567007e5862fd7254689937fcc492be3f66d906cf03df64225afb117462991d977ef6a1fd8fb87e947e3f9c103f07fb0b7513ebf225df4a660
7
+ data.tar.gz: 332d22105cbc7eb13ded7e8ca2aa84a01e8d2debd22021977e42a27c1c4d80705f90c757d27c5d4cc8c421acf7a5e501130b6e5d4c7575853c3745e40e06e805
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ Gemfile.lock
49
+ .ruby-version
50
+ .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
57
+
58
+ # rspec
59
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7
6
+ before_install: gem install bundler -v 2.1
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dsndb.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Manabu Niseki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # dnsdb
2
+
3
+ [![Build Status](https://travis-ci.com/ninoseki/dnsdb.svg?branch=master)](https://travis-ci.com/ninoseki/dnsdb)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/dnsdb/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/dnsdb?branch=master)
5
+ [![CodeFactor](https://www.codefactor.io/repository/github/ninoseki/dnsdb/badge)](https://www.codefactor.io/repository/github/ninoseki/dnsdb)
6
+
7
+ DNSDB API wrapper for Ruby.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'dsndb'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ bundle install
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```bash
26
+ gem install dsndb
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ # when given nothing, it tries to load your API key via ENV["DNSDB_API_KEY"]
33
+ api = DNSDB::API.new
34
+ # or you can set it manually
35
+ api = DNSDB::API.new("YOUR_API_KEY")
36
+
37
+ api.lookup.rdata(value: "10.0.0.1", type: "ip")
38
+ api.lookup.rdata(value: "github.com", type: "name")
39
+
40
+ api.lookup.rrset(owner_name: "www.farsightsecurity.com")
41
+ api.lookup.rrset(owner_name: "*.farsightsecurity.com", rrtype: "ns", bailiwick: "farsightsecurity.com")
42
+ api.lookup.rrset(owner_name: "*.farsightsecurity.com", rrtype: "ns", bailiwick: "farsightsecurity.com", limit: 100, time_last_after: 1_468_281_600)
43
+
44
+ api.summarize.rdata(rrtype: "ANY", value: "10.0.0.1", type: "ip")
45
+ api.summarize.rdata(value: "github.com", type: "name")
46
+
47
+ api.summarize.rrset(owner_name: "www.farsightsecurity.com")
48
+ api.summarize.rrset(owner_name: "*.farsightsecurity.com", rrtype: "ns", bailiwick: "farsightsecurity.com")
49
+ ```
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dsndb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dnsdb.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/dnsdb/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dnsdb"
7
+ spec.version = DNSDB::VERSION
8
+ spec.authors = ["Manabu Niseki"]
9
+ spec.email = ["manabu.niseki@gmail.com"]
10
+
11
+ spec.summary = "DNSDB API wrapper for Ruby"
12
+ spec.description = "DNSDB API wrapper for Ruby"
13
+ spec.homepage = "https://github.com/ninoseki/dnsdb"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.1"
29
+ spec.add_development_dependency "coveralls", "~> 0.8"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.9"
32
+ spec.add_development_dependency "vcr", "~> 5.1"
33
+ spec.add_development_dependency "webmock", "~> 3.8"
34
+ end
data/lib/dnsdb/api.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DNSDB
4
+ class API
5
+ def initialize(api_key = ENV["DNSDB_API_KEY"])
6
+ @api_key = api_key
7
+ end
8
+
9
+ def lookup
10
+ @lookup ||= Clients::Lookup.new(@api_key)
11
+ end
12
+
13
+ def summarize
14
+ @summarize ||= Clients::Summarize.new(@api_key)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/https"
5
+ require "uri"
6
+
7
+ module DNSDB
8
+ module Clients
9
+ class Client
10
+ HOST = "api.dnsdb.info"
11
+ BASE_URL = "https://#{HOST}/"
12
+
13
+ def initialize(api_key)
14
+ @api_key = api_key
15
+ end
16
+
17
+ private
18
+
19
+ def url_for(path)
20
+ URI(BASE_URL + path)
21
+ end
22
+
23
+ def https_options
24
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
25
+ uri = URI(proxy)
26
+ {
27
+ proxy_address: uri.hostname,
28
+ proxy_port: uri.port,
29
+ proxy_from_env: false,
30
+ use_ssl: true
31
+ }
32
+ else
33
+ { use_ssl: true }
34
+ end
35
+ end
36
+
37
+ def make_request(req)
38
+ Net::HTTP.start(HOST, 443, https_options) do |http|
39
+ response = http.request(req)
40
+
41
+ code = response.code.to_i
42
+ body = response.body
43
+
44
+ case code
45
+ when 200
46
+ json = body.lines.map do |line|
47
+ JSON.parse line.chomp
48
+ end
49
+ yield json
50
+ else
51
+ error = body.chomp
52
+ raise Error, "Unsupported response code returned: #{code} - #{error}"
53
+ end
54
+ end
55
+ end
56
+
57
+ def build_request(type: "GET", path:, params: {}); end
58
+
59
+ def _get(path, params, &block)
60
+ uri = url_for(path)
61
+ uri.query = URI.encode_www_form(params)
62
+ request = Net::HTTP::Get.new(uri)
63
+
64
+ request["Accept"] = "application/json"
65
+ request["X-Api-Key"] = @api_key
66
+
67
+ make_request(request, &block)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DNSDB
4
+ module Clients
5
+ class Lookup < Client
6
+ def rdata(type:, value:, rrtype: nil, **params)
7
+ path = if type == "ip"
8
+ "/lookup/rdata/ip/#{value}"
9
+ elsif rrtype
10
+ "/lookup/rdata/name/#{value}/#{rrtype}"
11
+ else
12
+ "/lookup/rdata/name/#{value}"
13
+ end
14
+
15
+ _get(path, params) { |json| json }
16
+ end
17
+
18
+ def rrset(owner_name:, rrtype: nil, bailiwick: nil, **params)
19
+ path = if bailiwick
20
+ rrtype ||= "ANY"
21
+ "/lookup/rrset/name/#{owner_name}/#{rrtype}/#{bailiwick}"
22
+ elsif rrtype
23
+ "/lookup/rrset/name/#{owner_name}/#{rrtype}"
24
+ else
25
+ "/lookup/rrset/name/#{owner_name}"
26
+ end
27
+
28
+ _get(path, params) { |json| json }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DNSDB
4
+ module Clients
5
+ class Summarize < Client
6
+ def rdata(type:, value:, rrtype: "ANY", **params)
7
+ path = if type == "ip"
8
+ "/summarize/rdata/ip/#{value}"
9
+ elsif rrtype
10
+ "/summarize/rdata/name/#{value}/#{rrtype}"
11
+ else
12
+ "/summarize/rdata/name/#{value}"
13
+ end
14
+
15
+ _get(path, params, &:first)
16
+ end
17
+
18
+ def rrset(owner_name:, rrtype: nil, bailiwick: nil, **params)
19
+ path = if bailiwick
20
+ rrtype ||= "ANY"
21
+ "/summarize/rrset/name/#{owner_name}/#{rrtype}/#{bailiwick}"
22
+ elsif rrtype
23
+ "/summarize/rrset/name/#{owner_name}/#{rrtype}"
24
+ else
25
+ "/summarize/rrset/name/#{owner_name}"
26
+ end
27
+
28
+ _get(path, params, &:first)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DNSDB
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dnsdb.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dnsdb/version"
4
+
5
+ require "dnsdb/clients/client"
6
+ require "dnsdb/clients/lookup"
7
+ require "dnsdb/clients/summarize"
8
+
9
+ require "dnsdb/api"
10
+
11
+ module DNSDB
12
+ class Error < StandardError; end
13
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dnsdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ description: DNSDB API wrapper for Ruby
98
+ email:
99
+ - manabu.niseki@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - dnsdb.gemspec
114
+ - lib/dnsdb.rb
115
+ - lib/dnsdb/api.rb
116
+ - lib/dnsdb/clients/client.rb
117
+ - lib/dnsdb/clients/lookup.rb
118
+ - lib/dnsdb/clients/summarize.rb
119
+ - lib/dnsdb/version.rb
120
+ homepage: https://github.com/ninoseki/dnsdb
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ homepage_uri: https://github.com/ninoseki/dnsdb
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 2.3.0
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.1.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: DNSDB API wrapper for Ruby
144
+ test_files: []