Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created April 22, 2015 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rklemme/3691be310c67c4a596d6 to your computer and use it in GitHub Desktop.
Save rklemme/3691be310c67c4a596d6 to your computer and use it in GitHub Desktop.
require 'socket'
ARGF.each do |line|
if /^\s*(\S+)\s+((?:\d{1,3}\.){3}\d{1,3})(?!\d)/ =~ line
host = $1
listed_ip = $2
begin
addrinfo = Socket::getaddrinfo(host, nil, :INET)
returned_ips = addrinfo.map {|a| a[3]}
puts "#{host}: Listed #{listed_ip} Returned IPs #{returned_ips.join ", "}."
rescue SocketError => e
$stderr.puts "Oops: #{e} for: #{host} #{listed_ip}"
end
else
$stderr.puts "Ignoring #{line}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment