Skip to content

Commit 4ad7d46

Browse files
committed
Merge pull request #17 from LubyRuffy/es
add dnsquery
2 parents 01e059f + a3c6fed commit 4ad7d46

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tools/dnsquery.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
require 'domainatrix'
3+
4+
def get_ip_of_host(host)
5+
require 'socket'
6+
ip = Socket.getaddrinfo(host, nil)
7+
return nil if !ip || !ip[0] || !ip[0][2]
8+
ip[0][2]
9+
rescue => e
10+
nil
11+
end
12+
13+
def get_root_of_host(host)
14+
begin
15+
url = Domainatrix.parse(host)
16+
if url.domain && url.public_suffix
17+
return url.domain+'.'+url.public_suffix
18+
end
19+
rescue => e
20+
return nil
21+
end
22+
end
23+
24+
STDOUT.sync = true
25+
while host = gets
26+
host = host.strip
27+
break unless host && host.size>1
28+
ip = get_ip_of_host(host)
29+
next unless ip
30+
rootdomain = get_root_of_host(host)
31+
#break unless rootdomain
32+
puts host+"\t"+rootdomain+"\t"+ip
33+
end

0 commit comments

Comments
 (0)