reversed 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2a0f5332c4c10206b8d14fc18a84d8faf2469fd
4
- data.tar.gz: e2845ea93f46a5cee9321874b8be2f712c6171a0
2
+ SHA256:
3
+ metadata.gz: e3b4c985d2b327609a7949bc759185fb4c168c9eeee9d4027d39d100468e9ff1
4
+ data.tar.gz: 61413538ab3f1ca493f1704906ac3560dd914eb36facf3560b85d804743ef991
5
5
  SHA512:
6
- metadata.gz: fbb064aded74596ddb6c2520a381ec28de82abf3b56fc91f640bed215ca0f2c7d1fcd6219dfedf48d622987749e0e91abef7966dc44691dc534f13e0afd421be
7
- data.tar.gz: 81c4f5a32c44a2613401bb8fefc6a8f029959e784fb597d91dc0d4cee3705cc00157f8e17f8785a73cf2095b08bbfc1eb26f0ce97fafa5f0b3bf60f9e20dd58b
6
+ metadata.gz: 782b5033b06e3ec7ce06f138c4e5c43c68779471553fa187b314c27be9a01931d871b080b1280cd9448293d18cfc299fe4ee437a9c2132a2a7956fb714686582
7
+ data.tar.gz: 964caee270849d6671363c1085a36edcc091acdfab250a54f0eebb0697b4ba7d3c058550ccbe8131f4d89f1e2292aef797d1bb84bed50b8def80edeb0e0a6a5c
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+
3
+ - Added support for machines with IPv6 disabled
4
+ - Raise `ArgumentError` for invalid IP
5
+
1
6
  ## 0.2.1
2
7
 
3
8
  - Added `timeout` and `nameservers` options
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016-2019 Andrew Kane
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.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```ruby
6
6
  Reversed.lookup("8.8.4.4")
7
- # "google-public-dns-b.google.com"
7
+ # "dns.google"
8
8
  ```
9
9
 
10
10
  Works with IPv4 and IPv6
@@ -14,6 +14,8 @@ Reversed.lookup("2a03:2880:2110:df07:face:b00c::1")
14
14
  # "a.ns.facebook.com"
15
15
  ```
16
16
 
17
+ [![Build Status](https://travis-ci.org/ankane/reversed.svg?branch=master)](https://travis-ci.org/ankane/reversed)
18
+
17
19
  ## Installation
18
20
 
19
21
  Add this line to your application’s Gemfile:
@@ -28,6 +30,20 @@ And then execute:
28
30
  bundle
29
31
  ```
30
32
 
33
+ ## Reference
34
+
35
+ Set timeout
36
+
37
+ ```ruby
38
+ Reversed.lookup(ip, timeout: 3)
39
+ ```
40
+
41
+ Set nameservers
42
+
43
+ ```ruby
44
+ Reversed.lookup(ip, nameservers: ["8.8.8.8"])
45
+ ```
46
+
31
47
  ## History
32
48
 
33
49
  View the [changelog](https://github.com/ankane/reversed/blob/master/CHANGELOG.md)
@@ -1,23 +1,35 @@
1
1
  require "reversed/version"
2
2
  require "net/dns"
3
+ require "ipaddr"
3
4
 
4
5
  module Reversed
5
6
  def self.lookup(ip, timeout: 5, nameservers: nil)
6
7
  ip = ip.to_s
7
8
  unless ip.empty?
9
+ begin
10
+ # ensure valid ip
11
+ ip = IPAddr.new(ip)
12
+ rescue IPAddr::InvalidAddressError
13
+ raise ArgumentError, "Invalid IP"
14
+ end
15
+
8
16
  options = {
9
- retry: 3,
17
+ retry_number: 3,
10
18
  udp_timeout: timeout
11
19
  }
12
20
  options[:nameservers] = nameservers if nameservers
13
21
  begin
14
- resolver = Net::DNS::Resolver.new(options).search(ip)
22
+ resolver = Net::DNS::Resolver.new(options).search(ip.reverse, Net::DNS::PTR)
15
23
  answer = resolver.answer.first || resolver.authority.first
16
24
  if answer && !answer.value.empty?
17
25
  answer.value.split(" ").first[0..-2]
18
26
  end
19
27
  rescue Net::DNS::Resolver::NoResponseError
20
28
  nil
29
+ rescue Errno::EAFNOSUPPORT
30
+ options[:use_tcp] = true
31
+ options[:tcp_timeout] = timeout
32
+ retry
21
33
  end
22
34
  end
23
35
  end
@@ -1,3 +1,3 @@
1
1
  module Reversed
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reversed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-dns
@@ -58,31 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '5'
69
69
  description:
70
- email:
71
- - andrew@chartkick.com
70
+ email: andrew@chartkick.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files: []
75
74
  files:
76
- - ".gitignore"
77
75
  - CHANGELOG.md
78
- - Gemfile
76
+ - LICENSE.txt
79
77
  - README.md
80
- - Rakefile
81
78
  - lib/reversed.rb
82
79
  - lib/reversed/version.rb
83
- - reversed.gemspec
84
80
  homepage: https://github.com/ankane/reversed
85
- licenses: []
81
+ licenses:
82
+ - MIT
86
83
  metadata: {}
87
84
  post_install_message:
88
85
  rdoc_options: []
@@ -92,15 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
89
  requirements:
93
90
  - - ">="
94
91
  - !ruby/object:Gem::Version
95
- version: '0'
92
+ version: '2.4'
96
93
  required_rubygems_version: !ruby/object:Gem::Requirement
97
94
  requirements:
98
95
  - - ">="
99
96
  - !ruby/object:Gem::Version
100
97
  version: '0'
101
98
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.11
99
+ rubygems_version: 3.0.3
104
100
  signing_key:
105
101
  specification_version: 4
106
102
  summary: Reverse DNS / IP Lookup for Ruby
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in reversed.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- t.warning = false
9
- end
10
-
11
- task default: :test
@@ -1,24 +0,0 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "reversed/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "reversed"
7
- spec.version = Reversed::VERSION
8
- spec.authors = ["Andrew Kane"]
9
- spec.email = ["andrew@chartkick.com"]
10
-
11
- spec.summary = "Reverse DNS / IP Lookup for Ruby"
12
- spec.homepage = "https://github.com/ankane/reversed"
13
-
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
- spec.bindir = "exe"
16
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_dependency "net-dns"
20
-
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "minitest"
24
- end