lost-socks 0.0.0 → 0.0.1
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.
- data/README.md +95 -0
- data/lib/lost-socks.rb +86 -4
- data/lost-socks.gemspec +2 -2
- metadata +2 -2
- data/lib/lost-socks/version.rb +0 -5
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
This library is for automating the resolution of DNS records, allowing you to
|
2
|
+
hit arbitrary name servers, and your own local DNS. If you have to migrate
|
3
|
+
a boatload of DNS, this library will allow you to verify your migration has
|
4
|
+
completed successfully and nothing has been left behind (something that is
|
5
|
+
very easy to do in these kinds of jobs).
|
6
|
+
|
7
|
+
NOTE: This requires that you have the *nix <code>dig</code> utility installed,
|
8
|
+
so it's probably safe to say that this library only work on linux/unix. It
|
9
|
+
hasn't been tested on Windows, so there!
|
10
|
+
|
11
|
+
If you're like me and you're fickle about hosting providers, you'd have done
|
12
|
+
this a few times. On the last migration I performed this saved me hours of
|
13
|
+
manual checking, and saved me from the embarressment of services disappearing
|
14
|
+
or whatnot. So let's walk through how you'd use that (full example source is
|
15
|
+
in example.rb).
|
16
|
+
|
17
|
+
First, you need to require the DNS library:
|
18
|
+
|
19
|
+
require 'lost-socks'
|
20
|
+
|
21
|
+
We'll set up some instance variables for the name servers we're going to check
|
22
|
+
against:
|
23
|
+
|
24
|
+
@local_dns = [nil]
|
25
|
+
@slicehost_dns = %w(ns1.slicehost.net ns2.slicehost.net)
|
26
|
+
|
27
|
+
To prevent name servers from blocking our dig requests, we'll put a delay of
|
28
|
+
one second in so that they don't start ignoring us (this happened to me a few
|
29
|
+
times, sometimes you can remove it, sometimes you can set it to a lower
|
30
|
+
threshold, experiment would you already!):
|
31
|
+
|
32
|
+
LostSocks.delay = 1
|
33
|
+
|
34
|
+
And the rest should be self-explainitory. The API is pretty damn intuitive if
|
35
|
+
you ask me after all, I wrote the damn thing). You can check A records, MX
|
36
|
+
records, CNAME records and even NS authority! Fwoar!
|
37
|
+
|
38
|
+
(@local_dns + @slicehost_dns).each do |server|
|
39
|
+
|
40
|
+
LostSocks.verify('yeahnah.org').with_server(server) do |it|
|
41
|
+
# checks A records
|
42
|
+
it.resolves_to('208.78.102.114')
|
43
|
+
# checks MX records
|
44
|
+
it.maps_mail_to('ASPMX.L.GOOGLE.COM', :priority => 10)
|
45
|
+
it.maps_mail_to('ALT1.ASPMX.L.GOOGLE.COM', :priority => 20)
|
46
|
+
it.maps_mail_to('ALT2.ASPMX.L.GOOGLE.COM', :priority => 30)
|
47
|
+
end
|
48
|
+
|
49
|
+
LostSocks.verify('www.yeahnah.org').with_server(server) do |it|
|
50
|
+
# checks CNAME records
|
51
|
+
it.is_aliased_to('yeahnah.org')
|
52
|
+
end
|
53
|
+
|
54
|
+
LostSocks.verify('tumble.yeahnah.org').with_server(server) do |it|
|
55
|
+
it.resolves_to('72.32.231.8') # tumblr :)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# shorthand that checks against your local dns
|
61
|
+
LostSocks.verify('yeahnah.org').resolves_to('208.78.102.114')
|
62
|
+
LostSocks.verify('tumble.yeahnah.org').resolves_to('72.32.231.8')
|
63
|
+
|
64
|
+
# oh, and check authorative ns :)
|
65
|
+
LostSocks.verify('yeahnah.org').has_authorative_nameserver_of('ns1.slicehost.net')
|
66
|
+
LostSocks.verify('yeahnah.org').has_authorative_nameserver_of('ns2.slicehost.net')
|
67
|
+
|
68
|
+
And this is the output the script will produce if everything works. If it fails
|
69
|
+
it'll say FAIL and print the dig output as well (this output is not shown here):
|
70
|
+
|
71
|
+
PASS: yeahnah.org A 208.78.102.114
|
72
|
+
PASS: yeahnah.org MX ASPMX.L.GOOGLE.COM {:priority=>10}
|
73
|
+
PASS: yeahnah.org MX ALT1.ASPMX.L.GOOGLE.COM {:priority=>20}
|
74
|
+
PASS: yeahnah.org MX ALT2.ASPMX.L.GOOGLE.COM {:priority=>30}
|
75
|
+
PASS: www.yeahnah.org CNAME yeahnah.org
|
76
|
+
PASS: tumble.yeahnah.org A 72.32.231.8
|
77
|
+
PASS: yeahnah.org A 208.78.102.114 @ns1.slicehost.net
|
78
|
+
PASS: yeahnah.org MX ASPMX.L.GOOGLE.COM @ns1.slicehost.net {:priority=>10}
|
79
|
+
PASS: yeahnah.org MX ALT1.ASPMX.L.GOOGLE.COM @ns1.slicehost.net {:priority=>20}
|
80
|
+
PASS: yeahnah.org MX ALT2.ASPMX.L.GOOGLE.COM @ns1.slicehost.net {:priority=>30}
|
81
|
+
PASS: www.yeahnah.org CNAME yeahnah.org @ns1.slicehost.net
|
82
|
+
PASS: tumble.yeahnah.org A 72.32.231.8 @ns1.slicehost.net
|
83
|
+
PASS: yeahnah.org A 208.78.102.114 @ns2.slicehost.net
|
84
|
+
PASS: yeahnah.org MX ASPMX.L.GOOGLE.COM @ns2.slicehost.net {:priority=>10}
|
85
|
+
PASS: yeahnah.org MX ALT1.ASPMX.L.GOOGLE.COM @ns2.slicehost.net {:priority=>20}
|
86
|
+
PASS: yeahnah.org MX ALT2.ASPMX.L.GOOGLE.COM @ns2.slicehost.net {:priority=>30}
|
87
|
+
PASS: www.yeahnah.org CNAME yeahnah.org @ns2.slicehost.net
|
88
|
+
PASS: tumble.yeahnah.org A 72.32.231.8 @ns2.slicehost.net
|
89
|
+
PASS: yeahnah.org A 208.78.102.114
|
90
|
+
PASS: tumble.yeahnah.org A 72.32.231.8
|
91
|
+
PASS: yeahnah.org NS ns1.slicehost.net
|
92
|
+
PASS: yeahnah.org NS ns2.slicehost.net
|
93
|
+
|
94
|
+
And that's about it! If you're using this library and enjoying it, please drop
|
95
|
+
me a line and let me know!
|
data/lib/lost-socks.rb
CHANGED
@@ -1,7 +1,89 @@
|
|
1
|
-
|
1
|
+
module LostSocks
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
VERSION = "0.0.1"
|
4
|
+
|
5
|
+
def self.delay=(seconds)
|
6
|
+
Verifier.delay = seconds
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.verify(domain)
|
10
|
+
Verifier.new(domain)
|
6
11
|
end
|
12
|
+
|
13
|
+
class Verifier
|
14
|
+
|
15
|
+
@@delay = nil
|
16
|
+
|
17
|
+
def self.delay=(seconds)
|
18
|
+
@@delay = seconds
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(domain)
|
22
|
+
@server = nil
|
23
|
+
@domain = domain
|
24
|
+
yield self if block_given?
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_server(server)
|
29
|
+
@server = server
|
30
|
+
yield self if block_given?
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def resolves_to(ip)
|
35
|
+
check! 'A', ip
|
36
|
+
end
|
37
|
+
|
38
|
+
def is_aliased_to(domain)
|
39
|
+
check! 'CNAME', domain
|
40
|
+
end
|
41
|
+
|
42
|
+
def maps_mail_to(domain, args = {})
|
43
|
+
check! 'MX', domain, args
|
44
|
+
end
|
45
|
+
|
46
|
+
# or it.answers_to ??
|
47
|
+
def has_authorative_nameserver_of(domain)
|
48
|
+
check! 'NS', domain
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def check!(query, against, args = {})
|
54
|
+
if ['A', 'CNAME', 'NS'].include?(query)
|
55
|
+
pattern = /#{@domain}\.\s+\d+\s+IN\s+#{query}\s+#{against}/
|
56
|
+
elsif query == 'MX'
|
57
|
+
pattern = /#{@domain}\.\s+\d+\s+IN\s+MX\s+#{args[:priority]}\s+#{against}/
|
58
|
+
else
|
59
|
+
raise "Unsupported query (#{query.inspect}): only A, CNAME and MX."
|
60
|
+
end
|
61
|
+
send(result!(query) =~ pattern ? :pass! : :fail!, query, against, args)
|
62
|
+
end
|
63
|
+
|
64
|
+
def result!(query)
|
65
|
+
@last_dig_command = if @server
|
66
|
+
"dig @#{@server} #{@domain} #{query}"
|
67
|
+
else
|
68
|
+
"dig #{@domain} #{query}"
|
69
|
+
end
|
70
|
+
sleep(@@delay) if @@delay
|
71
|
+
@last_dig_output = `#{@last_dig_command}`
|
72
|
+
end
|
73
|
+
|
74
|
+
def pass!(*args)
|
75
|
+
report! 'PASS', *args
|
76
|
+
end
|
77
|
+
|
78
|
+
def fail!(*args)
|
79
|
+
report! 'FAIL', *args
|
80
|
+
puts @last_dig_command
|
81
|
+
puts @last_dig_output
|
82
|
+
end
|
83
|
+
|
84
|
+
def report!(result, query, against, args = {})
|
85
|
+
puts "#{result}: #{@domain} #{query} #{against} #{"@#{@server}" if @server} #{args.inspect if args.any?}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
7
89
|
end
|
data/lost-socks.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "lost-socks
|
3
|
+
require "lost-socks"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "lost-socks"
|
7
|
-
s.version =
|
7
|
+
s.version = LostSocks::VERSION
|
8
8
|
s.authors = ["Ryan Allen"]
|
9
9
|
s.email = ["ryan@yeahnah.org"]
|
10
10
|
s.homepage = "https://github.com/ryan-allen/lost-socks"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lost-socks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,9 +23,9 @@ files:
|
|
23
23
|
- .gitignore
|
24
24
|
- Gemfile
|
25
25
|
- MIT-LICENSE
|
26
|
+
- README.md
|
26
27
|
- Rakefile
|
27
28
|
- lib/lost-socks.rb
|
28
|
-
- lib/lost-socks/version.rb
|
29
29
|
- lost-socks.gemspec
|
30
30
|
homepage: https://github.com/ryan-allen/lost-socks
|
31
31
|
licenses: []
|