-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LubyRuffy
authored and
LubyRuffy
committed
Apr 16, 2015
1 parent
05f27a9
commit a3c6fed
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |