dnslookup 0.3.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4de8b546e5c95a9c250a56c52dc0351ba11f1ffc0c02c490431623e60ba2697
4
- data.tar.gz: 20fd3fd059e88602f15671dd47e1b2ae72acc065c8e17a2bd61ab1ee54832f17
3
+ metadata.gz: ee4e5a965cfceb5404a336c75c7957d24b7d77e4ca370b386450a494c8442e56
4
+ data.tar.gz: d98e8daf75997c8df3f9ccd6fc90b9643376d17977d18f7240fbc378c129727a
5
5
  SHA512:
6
- metadata.gz: ec8a8f5aa96cc3f3998cfcee760fb5873a12f3360d2beed31c2e25c729e6d4b4edd241affc50215b7143c91c06bfec8a419c8776c6671243b37fa62d06e05474
7
- data.tar.gz: dbbe24b3f43b0285f6c98a3756c3b84cfe51731f011af742533f0749f02b7f64c0d5401ae8120921efe6476e18d9738322b6bf108b9ddec38e04454e3f9d33c4
6
+ metadata.gz: aad2d24318eba691eaba31f0fa69b315271ad0be20893f159157499c354c54fcc45f498e24825d65ff5200623e54aaed1c2d7e7d73928b1b518e62d1a4413aef
7
+ data.tar.gz: 3a097d3e994669632e534bb2550da4719a80584a7931c16de3d82d6379530da8167b62e50d5ec17e47f897b9329f48b08db0cea04b545e6c526da78fdf7f2652
data/CHANGELOG.md ADDED
@@ -0,0 +1,51 @@
1
+ # CHANGELOG
2
+
3
+ Noteworthy updates for each DNSLookup version are included here. For a complete changelog, see the git history.
4
+
5
+ ## [0.4.0] - 2026-03-31
6
+
7
+ ### Changed
8
+
9
+ - Fixed `-h` and `-v` so they work without requiring a domain argument
10
+ - Made the default lookup explicit by querying `A` records when no type flag is provided
11
+ - Improved security for safer argv-based call and report failed lookups separately from empty results
12
+ - Corrected `CNAME` queries
13
+ - Separated CLI argument parsing from query execution
14
+ - Refreshed the CLI documentation, tightened gem packaging metadata, and made the test suite deterministic
15
+ - Updated documentation to clarify installation requirements
16
+ - Expanded usage examples for default lookups
17
+
18
+ ## [0.3.1] - 2025-06-13
19
+
20
+ ### Changes
21
+
22
+ - General cleanup and maintenance
23
+
24
+ ## [0.3.0] - 2025-06-12
25
+
26
+ ### Changes
27
+
28
+ - Refactor gem source
29
+ - Refactor tests
30
+ - General cleanup and maintenance
31
+
32
+ ## [0.2.0] - 2024-02-08
33
+
34
+ ### New Features
35
+
36
+ - Added ability to check multiple record types at once.
37
+ - Updated core gem Ruby code and general code improvements.
38
+ - Updated tests.
39
+
40
+ ## [0.1.6] - 2023-02-06
41
+
42
+ ### Changes
43
+
44
+ - Added Ruby 3.0 to required versions.
45
+ - Spec bumps and general code improvements.
46
+
47
+ ## [0.1.0] - 2016-02-01
48
+
49
+ ### New Features
50
+
51
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 - 2024 Victor S. Keenan
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,127 @@
1
+ # dnslookup — A simple Ruby CLI tool for querying DNS records
2
+
3
+ ![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)
4
+ ![Ruby](https://img.shields.io/badge/ruby-%3E%3D3.0-red)
5
+ [![Issues](https://img.shields.io/github/issues/VictorSK/dnslookup)](https://github.com/VictorSK/dnslookup/issues)
6
+ [![Last Commit](https://img.shields.io/github/last-commit/VictorSK/dnslookup)](https://github.com/VictorSK/dnslookup/commits/main)
7
+ [![Gem Version](https://badge.fury.io/rb/dnslookup.svg)](https://badge.fury.io/rb/dnslookup)
8
+
9
+ **dnslookup** is a Ruby CLI for querying A, MX, CNAME, and TXT records from default or custom DNS servers. It wraps `dig` with a small command-line interface that is useful for quick troubleshooting, scripting, and day-to-day DNS checks.
10
+
11
+ Please use [GitHub Issues](https://github.com/VictorSK/dnslookup/issues) to report bugs.
12
+
13
+ ## Requirements
14
+
15
+ - Ruby 3.0 or newer
16
+ - The `dig` executable available on your `PATH`
17
+
18
+ If `dig` is not already installed, common package names are:
19
+
20
+ ```bash
21
+ brew install bind
22
+ ```
23
+
24
+ ```bash
25
+ sudo apt-get install dnsutils
26
+ ```
27
+
28
+ ## Installation
29
+
30
+ To add dnslookup to an existing project, add this line to your project's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'dnslookup'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ ```bash
39
+ bundle install
40
+ ```
41
+
42
+ Or to install the CLI locally:
43
+
44
+ ```bash
45
+ gem install dnslookup
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ Lookup DNS records for a domain:
51
+
52
+ ```bash
53
+ dnslookup example.com -a
54
+ ```
55
+
56
+ If you omit a record-type option, `dnslookup` queries `A` records by default:
57
+
58
+ ```bash
59
+ dnslookup example.com
60
+ ```
61
+
62
+ By default, `dnslookup` queries Google's public resolvers: `8.8.8.8` and `8.8.4.4`. Use `-s` to query a specific resolver.
63
+
64
+ ### Options
65
+
66
+ | Option | Description |
67
+ | ------------------- | ------------------------------------ |
68
+ | `-m`, `--mx` | Return only MX records |
69
+ | `-a`, `--aname` | Return only A records |
70
+ | `-c`, `--cname` | Return only CNAME records |
71
+ | `-t`, `--txt` | Return only TXT records |
72
+ | `-A`, `--all` | Return A, MX, CNAME, and TXT records |
73
+ | `-s`, `--server=IP` | Query a specific name server IP |
74
+ | `-h`, `--help` | Show help message |
75
+ | `-v`, `--version` | Show gem version |
76
+
77
+ ### Examples
78
+
79
+ Lookup the default `A` record:
80
+
81
+ ```bash
82
+ dnslookup example.com
83
+ ```
84
+
85
+ Lookup a `CNAME` record explicitly:
86
+
87
+ ```bash
88
+ dnslookup ftp.victorkeenan.com -c
89
+ ```
90
+
91
+ Query a specific name server:
92
+
93
+ ```bash
94
+ dnslookup example.com -a -s1.1.1.1
95
+ ```
96
+
97
+ Query all supported record types at once:
98
+
99
+ ```bash
100
+ dnslookup example.com --all
101
+ ```
102
+
103
+ If `dig` cannot complete the lookup, `dnslookup` reports the query as failed instead of showing an empty result:
104
+
105
+ ```bash
106
+ dnslookup example.com -a -s203.0.113.53
107
+ ```
108
+
109
+ Depending on the failure, the output will include either `(query failed)` or `(query failed: ...)`.
110
+
111
+ Help with usage and options:
112
+
113
+ ```bash
114
+ dnslookup -h
115
+ ```
116
+
117
+ ## Contributing
118
+
119
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/VictorSK/dnslookup). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the terms specified in the [CODE OF CONDUCT](CODE_OF_CONDUCT.md).
120
+
121
+ ## License
122
+
123
+ dnslookup is copyright © 2016-2026 Victor S. Keenan. It is free software and may be redistributed under the terms specified in the [LICENSE](LICENSE.txt) file.
124
+
125
+ ## Coded With Love
126
+
127
+ Code crafted by me, [Victor S. Keenan](https://www.victorkeenan.com). Find me on Twitter [@VictorSK](https://twitter.com/victorsk) or [hire me](https://www.inspyre.com) to design, develop, and grow your product or service.
data/bin/dnslookup CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'dnslookup'
4
4
 
5
- DNSLookup::Query.new
5
+ DNSLookup::CLI.run(argv: ARGV)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DNSLookup
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/dnslookup.rb CHANGED
@@ -2,26 +2,35 @@
2
2
 
3
3
  require_relative "dnslookup/version"
4
4
  require 'optparse'
5
+ require 'open3'
5
6
 
6
7
  module DNSLookup
7
8
  class Error < StandardError; end
8
- class Query
9
+ class CLI
9
10
  DEFAULT_SERVERS = ['8.8.8.8', '8.8.4.4'].freeze
10
11
 
11
- def initialize
12
+ def self.run(argv: ARGV, out: $stdout)
13
+ new(argv: argv, out: out).run
14
+ end
15
+
16
+ def initialize(argv: ARGV, out: $stdout)
17
+ @argv = argv.dup
18
+ @out = out
12
19
  @type = []
13
20
  @single_server = nil
14
- @domain = ARGV.shift
21
+ end
22
+
23
+ def run
24
+ parse_options
25
+ domain = @argv.shift
15
26
 
16
- if @domain.nil? || @domain.start_with?('-')
17
- puts "Error: You must specify a domain name.\n\n"
18
- puts "Usage: dnslookup <domain name> [options]"
27
+ if domain.nil? || domain.start_with?('-')
28
+ @out.puts "Error: You must specify a domain name.\n\n"
29
+ @out.puts "Usage: dnslookup <domain name> [options]"
19
30
  exit 1
20
31
  end
21
32
 
22
- parse_options
23
- setup_query_servers
24
- query_with_options
33
+ Query.new(domain: domain, types: @type, servers: query_servers, out: @out).run
25
34
  end
26
35
 
27
36
  def parse_options
@@ -39,29 +48,41 @@ module DNSLookup
39
48
  end
40
49
  opt.on("-A", "--all", "Return all record types") { @type = %w[a mx c txt] }
41
50
  opt.on("-h", "--help", "Prints this help") do
42
- puts opt
51
+ @out.puts opt
43
52
  exit
44
53
  end
45
54
  opt.on("-v", "--version", "Prints version") do
46
- puts DNSLookup::VERSION
55
+ @out.puts DNSLookup::VERSION
47
56
  exit
48
57
  end
49
- end.parse!
58
+ end.parse!(@argv)
50
59
  end
51
60
 
52
- def setup_query_servers
53
- @servers = []
61
+ def query_servers
62
+ return [@single_server] if @single_server
54
63
 
55
- if @single_server
56
- @servers << @single_server
57
- else
58
- @servers = DEFAULT_SERVERS
59
- end
64
+ DEFAULT_SERVERS
60
65
  end
66
+ end
61
67
 
62
- def query_with_options
68
+ class Query
69
+ RECORD_TYPES = {
70
+ 'a' => 'A',
71
+ 'mx' => 'MX',
72
+ 'c' => 'CNAME',
73
+ 'txt' => 'TXT'
74
+ }.freeze
75
+
76
+ def initialize(domain:, types: [], servers: CLI::DEFAULT_SERVERS, out: $stdout)
77
+ @domain = domain
78
+ @type = types
79
+ @servers = servers
80
+ @out = out
81
+ end
82
+
83
+ def run
63
84
  if @type.empty?
64
- query_command('any')
85
+ query_command('a')
65
86
  else
66
87
  query_command(@type)
67
88
  end
@@ -70,13 +91,32 @@ module DNSLookup
70
91
  def query_command(types)
71
92
  @servers.each do |server|
72
93
  Array(types).each do |type|
73
- record_type = type == 'any' ? '' : type.upcase
74
- check = `dig @#{server} #{@domain} #{record_type} +short`
75
- puts "Checking server: #{server} for #{record_type.empty? ? 'ALL' : record_type} records"
76
- puts check.empty? ? "(no records found)" : check
77
- puts
94
+ record_type = normalize_record_type(type)
95
+ check, error, status = Open3.capture3('dig', "@#{server}", @domain, record_type, '+short')
96
+ @out.puts "Checking server: #{server} for #{record_type} records"
97
+ @out.puts format_lookup_result(check: check, error: error, status: status)
98
+ @out.puts
78
99
  end
79
100
  end
101
+ rescue Errno::ENOENT
102
+ @out.puts "(query failed: dig command not found)"
103
+ @out.puts
104
+ end
105
+
106
+ private
107
+
108
+ def normalize_record_type(type)
109
+ RECORD_TYPES.fetch(type.to_s.downcase, type.to_s.upcase)
110
+ end
111
+
112
+ def format_lookup_result(check:, error:, status:)
113
+ return check if status.success? && !check.empty?
114
+ return "(no records found)" if status.success?
115
+
116
+ error_message = error.to_s.strip
117
+ return "(query failed)" if error_message.empty?
118
+
119
+ "(query failed: #{error_message})"
80
120
  end
81
121
  end
82
122
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnslookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor S. Keenan
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A Ruby CLI tool to query DNS records from multiple public or custom name
13
13
  servers, providing fast and flexible DNS lookups.
@@ -18,6 +18,9 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ - README.md
21
24
  - bin/dnslookup
22
25
  - lib/dnslookup.rb
23
26
  - lib/dnslookup/version.rb
@@ -45,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
48
  - !ruby/object:Gem::Version
46
49
  version: '0'
47
50
  requirements: []
48
- rubygems_version: 3.6.3
51
+ rubygems_version: 4.0.9
49
52
  specification_version: 4
50
53
  summary: A simple Ruby CLI tool for querying DNS records.
51
54
  test_files: []