nslookupot 0.0.1 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0846a02a74eb40953b233d52b2b8f38f12414f8b3bf9c06c7eb2603129100428'
4
- data.tar.gz: ab65aa27f3980d3bad019c6711258111da627298a3a07e63deb781550dda7ed3
3
+ metadata.gz: b9f55a82dd8b59575552ff6ec51ce460d3960edc9802ae7b0ad7b34acf9ecdb2
4
+ data.tar.gz: f5fafc615a8bcd14b230f29ca719dd43bebd48a4e91bbabd449936ad1ef20df2
5
5
  SHA512:
6
- metadata.gz: 4ef75c8b9bd0b4acebec3255714f853a1b777f2e0132d9018dd094b5ff394e063439e68dc9f60621558964e5f73e4a0d2b332978b33078b54c29513f50ca94fd
7
- data.tar.gz: aa3653f20ebd41e739f9d7aa7c24356ad037b6d333aed83da6f8d7c9b33d82f39c50a516229cb547222b3e309bc309543dc51ad21d7d6f05c9c41d84a9fad7b2
6
+ metadata.gz: 4f9c2a07724a2f6ee9cb15b396360bd47e5a33ca7b17eb3be151cbc93d1c2111a91c60dbe362a7277af0cc646a556279ccfca08e7e3328cade8acb453bcdd273
7
+ data.tar.gz: 3663e91a31ac98e0d638be5bc182b66c776322fe7aeb0d6ad92d6cfea6a4d6b4d7a0ea885935cf797534d24f9c69eb1d622127765fecc088d86b842209e95de7
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ ci:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['2.6.x', '2.7.x']
17
+ steps:
18
+ - name: Set up Ruby
19
+ uses: actions/setup-ruby@v1
20
+ - uses: actions/checkout@v1
21
+ - name: Install dependencies
22
+ run: |
23
+ gem --version
24
+ gem install bundler
25
+ bundle --version
26
+ bundle install
27
+ - name: Run test
28
+ run: |
29
+ bundle exec rake
@@ -16,5 +16,5 @@ Metrics/AbcSize:
16
16
  Metrics/MethodLength:
17
17
  Max: 30
18
18
 
19
- Naming/UncommunicativeMethodParamName:
19
+ Naming/MethodParameterName:
20
20
  MinNameLength: 1
data/Gemfile CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ gem 'caa_rr_patch'
5
6
  gem 'openssl'
6
7
  gem 'rake'
7
8
 
8
9
  group :test do
9
- gem 'pry'
10
- gem 'pry-byebug'
10
+ gem 'byebug'
11
11
  gem 'rspec', '3.8.0'
12
- gem 'rubocop', '0.68.1'
12
+ gem 'rubocop', '0.78.0'
13
13
  end
14
14
 
15
15
  gemspec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # nslookupot
2
2
 
3
- [![Build Status](https://travis-ci.org/thekuwayama/nslookupot.svg?branch=master)](https://travis-ci.org/thekuwayama/nslookupot)
3
+ [![Gem Version](https://badge.fury.io/rb/nslookupot.svg)](https://badge.fury.io/rb/nslookupot)
4
+ [![CI](https://github.com/thekuwayama/nslookupot/workflows/CI/badge.svg)](https://github.com/thekuwayama/nslookupot/actions?workflow=CI)
4
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/5df9157757f5a0bf1623/maintainability)](https://codeclimate.com/github/thekuwayama/nslookupot/maintainability)
5
6
 
6
7
  nslookupot is CLI that is `nslookup` over TLS (version 1.2).
@@ -23,6 +24,7 @@ Usage: nslookupot [options] name
23
24
  -s, --server VALUE the name server IP address (default 1.1.1.1)
24
25
  -p, --port VALUE the name server port number (default 853)
25
26
  -h, --hostname VALUE the name server hostname (default cloudflare-dns.com)
27
+ -n, --no-check-sni no check SNI (default false)
26
28
  -t, --type VALUE the type of the information query (default A)
27
29
  ```
28
30
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'caa_rr_patch'
3
4
  require 'resolv'
4
5
  require 'socket'
5
6
  require 'openssl'
@@ -12,7 +12,8 @@ module Nslookupot
12
12
  opts = {
13
13
  server: '1.1.1.1',
14
14
  port: 853,
15
- hostname: 'cloudflare-dns.com'
15
+ hostname: 'cloudflare-dns.com',
16
+ check_sni: true
16
17
  }
17
18
  type = 'A'
18
19
 
@@ -40,6 +41,14 @@ module Nslookupot
40
41
  opts[:hostname] = v
41
42
  end
42
43
 
44
+ op.on(
45
+ '-n',
46
+ '--no-check-sni',
47
+ "no check SNI (default #{!opts[:check_sni]})"
48
+ ) do
49
+ opts[:check_sni] = false
50
+ end
51
+
43
52
  op.on(
44
53
  '-t',
45
54
  '--type VALUE',
@@ -52,21 +61,21 @@ module Nslookupot
52
61
  begin
53
62
  args = op.parse(argv)
54
63
  rescue OptionParser::InvalidOption => e
55
- puts op.to_s
56
- puts "error: #{e.message}"
64
+ warn op.to_s
65
+ warn "error: #{e.message}"
57
66
  exit 1
58
67
  end
59
68
 
60
69
  begin
61
70
  type = s2typeclass(type)
62
71
  rescue NameError
63
- puts "error: unknown query type #{type}"
72
+ warn "error: unknown query type #{type}"
64
73
  exit 1
65
74
  end
66
75
 
67
76
  if args.size != 1
68
- puts op.to_s
69
- puts 'error: number of arguments is not 1'
77
+ warn op.to_s
78
+ warn 'error: number of arguments is not 1'
70
79
  exit 1
71
80
  end
72
81
 
@@ -75,20 +84,23 @@ module Nslookupot
75
84
  # rubocop: enable Metrics/MethodLength
76
85
 
77
86
  def s2typeclass(s)
78
- Resolv::DNS::Resource::IN.const_get(s.upcase)
87
+ rr = Resolv::DNS::Resource::IN.const_get(s.upcase)
88
+ raise NameError unless rr < Resolv::DNS::Resource
89
+
90
+ rr
79
91
  end
80
92
 
81
93
  def run
82
94
  opts, name, type = parse_options
83
95
 
84
- resolver = Nslookupot::Resolver.new(opts)
96
+ resolver = Nslookupot::Resolver.new(**opts)
85
97
  puts 'Address:'.ljust(16) + opts[:server] + '#' + opts[:port].to_s
86
98
  puts '--'
87
99
  resolver.resolve_resources(name, type).each do |rr|
88
100
  puts 'Name:'.ljust(16) + name
89
- rr.instance_variables.each do |v|
90
- k = (v[1..].capitalize + ':').ljust(16)
91
- v = rr.instance_variable_get(v).to_s
101
+ rr.instance_variables.each do |var|
102
+ k = (var[1..].capitalize + ':').ljust(16)
103
+ v = rr.instance_variable_get(var).to_s
92
104
  puts k + v
93
105
  end
94
106
  puts ''
@@ -5,11 +5,17 @@ module Nslookupot
5
5
  # @param server [String]
6
6
  # @param port [Integer]
7
7
  # @param hostname [String]
8
- def initialize(server: '1.1.1.1', port: 853,
9
- hostname: 'cloudflare-dns.com')
8
+ # @param check_sni [bool]
9
+ def initialize(
10
+ server: '1.1.1.1',
11
+ port: 853,
12
+ hostname: 'cloudflare-dns.com',
13
+ check_sni: true
14
+ )
10
15
  @server = server
11
16
  @port = port
12
17
  @hostname = hostname # for SNI
18
+ @check_sni = check_sni
13
19
  end
14
20
 
15
21
  # @param name [String]
@@ -70,10 +76,16 @@ module Nslookupot
70
76
  def gen_sock
71
77
  ts = TCPSocket.new(@server, @port)
72
78
  ctx = OpenSSL::SSL::SSLContext.new('TLSv1_2')
79
+ ctx.alpn_protocols = ['dot']
73
80
  sock = OpenSSL::SSL::SSLSocket.new(ts, ctx)
74
81
  sock.sync_close = true
75
- sock.connect
76
- sock.post_connection_check(@hostname)
82
+ if @check_sni
83
+ sock.hostname = @hostname
84
+ sock.connect
85
+ sock.post_connection_check(@hostname)
86
+ else
87
+ sock.connect
88
+ end
77
89
 
78
90
  sock
79
91
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nslookupot
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.6'
5
5
  end
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = ['nslookupot']
23
23
 
24
24
  spec.add_development_dependency 'bundler'
25
+ spec.add_dependency 'caa_rr_patch'
25
26
  spec.add_dependency 'openssl'
26
27
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe Nslookupot::CLI do
6
+ context 'Resource Record (RR) TYPEs' do
7
+ let(:cli) do
8
+ Nslookupot::CLI.new
9
+ end
10
+
11
+ it 'could return the typeclass object' do
12
+ expect(cli.s2typeclass('A')).to eq Resolv::DNS::Resource::IN::A
13
+ expect(cli.s2typeclass('AAAA')).to eq Resolv::DNS::Resource::IN::AAAA
14
+ expect(cli.s2typeclass('CNAME')).to eq Resolv::DNS::Resource::IN::CNAME
15
+ expect(cli.s2typeclass('HINFO')).to eq Resolv::DNS::Resource::IN::HINFO
16
+ expect(cli.s2typeclass('MINFO')).to eq Resolv::DNS::Resource::IN::MINFO
17
+ expect(cli.s2typeclass('MX')).to eq Resolv::DNS::Resource::IN::MX
18
+ expect(cli.s2typeclass('NS')).to eq Resolv::DNS::Resource::IN::NS
19
+ expect(cli.s2typeclass('PTR')).to eq Resolv::DNS::Resource::IN::PTR
20
+ expect(cli.s2typeclass('SOA')).to eq Resolv::DNS::Resource::IN::SOA
21
+ expect(cli.s2typeclass('TXT')).to eq Resolv::DNS::Resource::IN::TXT
22
+ expect(cli.s2typeclass('WKS')).to eq Resolv::DNS::Resource::IN::WKS
23
+ expect(cli.s2typeclass('CAA')).to eq Resolv::DNS::Resource::IN::CAA
24
+ end
25
+
26
+ it 'could raise NameError' do
27
+ expect { cli.s2typeclass('ANY') }.to raise_error(NameError)
28
+ expect { cli.s2typeclass('ClassValue') }.to raise_error(NameError)
29
+ expect { cli.s2typeclass('hoge') }.to raise_error(NameError)
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nslookupot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekuwayama
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-03 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: caa_rr_patch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: openssl
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -46,9 +60,9 @@ executables:
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
63
+ - ".github/workflows/ci.yml"
49
64
  - ".gitignore"
50
65
  - ".rubocop.yml"
51
- - ".travis.yml"
52
66
  - Gemfile
53
67
  - LICENSE.txt
54
68
  - README.md
@@ -59,13 +73,14 @@ files:
59
73
  - lib/nslookupot/resolver.rb
60
74
  - lib/nslookupot/version.rb
61
75
  - nslookupot.gemspec
76
+ - spec/cli_spec.rb
62
77
  - spec/resolver_spec.rb
63
78
  - spec/spec_helper.rb
64
79
  homepage: https://github.com/thekuwayama/nslookupot
65
80
  licenses:
66
81
  - MIT
67
82
  metadata: {}
68
- post_install_message:
83
+ post_install_message:
69
84
  rdoc_options: []
70
85
  require_paths:
71
86
  - lib
@@ -80,10 +95,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
95
  - !ruby/object:Gem::Version
81
96
  version: '0'
82
97
  requirements: []
83
- rubygems_version: 3.0.3
84
- signing_key:
98
+ rubygems_version: 3.1.2
99
+ signing_key:
85
100
  specification_version: 4
86
101
  summary: nslookup over TLS
87
102
  test_files:
103
+ - spec/cli_spec.rb
88
104
  - spec/resolver_spec.rb
89
105
  - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- sudo: false
2
-
3
- language: ruby
4
-
5
- rvm:
6
- - 2.6.3
7
- - ruby-head
8
-
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head
12
-
13
- before_install:
14
- - gem install bundler
15
- - bundle install
16
-
17
- script: bundle exec rake