From a3c6fed9428efd774ca61a5faea49fd6ab821fae Mon Sep 17 00:00:00 2001 From: LubyRuffy Date: Thu, 16 Apr 2015 15:44:19 +0800 Subject: [PATCH] add dnsquery --- tools/dnsquery.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 tools/dnsquery.rb diff --git a/tools/dnsquery.rb b/tools/dnsquery.rb new file mode 100755 index 0000000..28752d6 --- /dev/null +++ b/tools/dnsquery.rb @@ -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