Skip to content

Instantly share code, notes, and snippets.

@mattbailey
Created November 26, 2011 06:38
Show Gist options
  • Save mattbailey/1395184 to your computer and use it in GitHub Desktop.
Save mattbailey/1395184 to your computer and use it in GitHub Desktop.
getip()
# net-dns gem
require 'net/dns/resolver'
# This is where the net-dns resolver makes queries
ENV['RES_NAMESERVERS'] = '111.222.333.444'
def getip(name)
ip = IPAddr.new
Resolver(name).each_address do |address|
ip = address
end
if ip == '::'
raise "invalid host"
else
return ip.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment