Created
November 26, 2011 06:38
-
-
Save mattbailey/1395184 to your computer and use it in GitHub Desktop.
getip()
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
# 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