Permalink
Browse files

domain-grabber looksup DNS records

  • Loading branch information...
1 parent f71e1e7 commit c25f663fabac35804bee611b9c358943d46763e3 @chao-mu committed Feb 26, 2012
Showing with 43 additions and 14 deletions.
  1. +43 −14 bin/domain-grabber.rb
View
@@ -2,39 +2,68 @@
load File.join(File.dirname(__FILE__), '..', 'config', 'setup.rb')
-require 'exhumer/module'
+require 'exhumer/module'
+require 'public_suffix'
+require 'net/dns/resolver'
+require 'pp'
if ARGV.length < 1
- warn "synopsis: #{$0} <bing id> [ip, ..]"
+ warn "synopsis: #{$0} <bing app id> [ip, ..]"
warn "usage example: #{$0} EEB3EB8871DCCD5639E692A5A55A023957D04EC1 206.220.193.152 4.59.136.200"
exit 2
end
app_id, ips = ARGV
ips = [ips].flatten
-def domain_lookup(app_id, ips, &f)
- ips.each do |ip|
- bing_domain_lookup(app_id, ip, &f)
- end
+def google_domain_lookup(ip)
+ bing_path = File.join(MODULE_DIR, 'search', 'google.rb')
+ bing_mod = Exhumer::Module.load_module(bing_path)
end
-def bing_domain_lookup(app_id, ip, &f)
+def bing_reverse_lookup(app_id, ip)
bing_path = File.join(MODULE_DIR, 'search', 'bing.rb')
bing_mod = Exhumer::Module.load_module(bing_path)
bing_opts = {
:app_id => app_id,
:query => "ip:#{ip}"
}
-
+ hosts = []
+
bing_mod.each(bing_opts) do |query, uri, descr|
- f.call(uri.host)
+ hosts << uri.host
end
+
+ hosts.uniq
+end
+
+def lookup_records(domains, record_type)
+ resolver = Net::DNS::Resolver.new
+
+ domains.map do |domain|
+ resolver.query(domain, record_type).answer
+ end.flatten
end
-host_history = {}
-domain_lookup(app_id, ips) do |host|
- unless host_history[host]
- puts host
- host_history[host] = true
+domains = ips.map do |ip|
+ bing_reverse_lookup(app_id, ip).each do |hostname|
+ [hostname, PublicSuffix.parse(hostname).domain]
+ end
+end.flatten.flatten.uniq
+
+# TODO: PTR lookups
+
+%w(A AAAA CNAME MX NS SOA SRV TXT).each do |type|
+ records = lookup_records(domains, type)
+
+ if records.count <= 0
+ next
+ end
+
+ puts '###'
+ puts "# #{type} Records"
+ puts '##'
+ records.each do |record|
+ puts record
end
+ puts "\n"
end

0 comments on commit c25f663

Please sign in to comment.