working through 14.4
This commit is contained in:
parent
ea74004d4e
commit
e69ebabc5f
29
cookbook/014/04-list-a-to-z-domain-addrs-concurrent.rb
Normal file
29
cookbook/014/04-list-a-to-z-domain-addrs-concurrent.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
require 'resolv'
|
||||||
|
require 'resolv-replace'
|
||||||
|
|
||||||
|
|
||||||
|
def multiple_lookup(*names)
|
||||||
|
dns = Resolv::DNS.new
|
||||||
|
results = {}
|
||||||
|
threads = []
|
||||||
|
names.each do |name|
|
||||||
|
threads << Thread.new(name) do |name|
|
||||||
|
begin
|
||||||
|
dns.each_address(name) { |a| (results[name] ||= []) << a }
|
||||||
|
rescue Resolv::ResolvError
|
||||||
|
results[name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
threads.each { |t| t.join }
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
domains = ("a".."z").collect { |l| l + '.com' }
|
||||||
|
multiple_lookup(*domains).sort.each do |name, addresses|
|
||||||
|
if addresses
|
||||||
|
puts "#{name}: #{addresses.size} " + \
|
||||||
|
"address#{addresses.size == 1 ? "" : "es"}"
|
||||||
|
end
|
||||||
|
end
|
11
cookbook/014/04-list-oreilly-mx-ns.rb
Normal file
11
cookbook/014/04-list-oreilly-mx-ns.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
require 'resolv'
|
||||||
|
|
||||||
|
dns = Resolv::DNS.new
|
||||||
|
domain = "oreilly.com"
|
||||||
|
dns.each_resource(domain, Resolv::DNS::Resource::IN::MX) do |mail_server|
|
||||||
|
puts mail_server.exchange
|
||||||
|
end
|
||||||
|
|
||||||
|
dns.each_resource(domain, Resolv::DNS::Resource::IN::NS) do |nameserver|
|
||||||
|
puts nameserver.name
|
||||||
|
end
|
3
cookbook/014/04.rb
Normal file
3
cookbook/014/04.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require 'resolv'
|
||||||
|
|
||||||
|
Resolv::DNS.new.each_address('oreilly.com') { |addr| puts addr }
|
Loading…
Reference in New Issue
Block a user