Skip to content

Commit

Permalink
Merge pull request #17 from LubyRuffy/es
Browse files Browse the repository at this point in the history
add dnsquery
  • Loading branch information
LubyRuffy committed Apr 22, 2015
2 parents 01e059f + a3c6fed commit 4ad7d46
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tools/dnsquery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby
require 'domainatrix'

def get_ip_of_host(host)
require 'socket'
ip = Socket.getaddrinfo(host, nil)
return nil if !ip || !ip[0] || !ip[0][2]
ip[0][2]
rescue => e
nil
end

def get_root_of_host(host)
begin
url = Domainatrix.parse(host)
if url.domain && url.public_suffix
return url.domain+'.'+url.public_suffix
end
rescue => e
return nil
end
end

STDOUT.sync = true
while host = gets
host = host.strip
break unless host && host.size>1
ip = get_ip_of_host(host)
next unless ip
rootdomain = get_root_of_host(host)
#break unless rootdomain
puts host+"\t"+rootdomain+"\t"+ip
end

0 comments on commit 4ad7d46

Please sign in to comment.