次のようなもの:
def domain_exists?(domain)
# perform check
# return true|false
end
puts "valid!" if domain_exists?("example.com")
次のようなもの:
def domain_exists?(domain)
# perform check
# return true|false
end
puts "valid!" if domain_exists?("example.com")
require 'socket'
def domain_exists?(domain)
begin
Socket.gethostbyname(domain)
rescue SocketError
return false
end
true
end
If you want to check whether a domain is registered or not, then you need to perform a Whois query. http://www.ruby-whois.org/
ruby-whois を使用するのはとても簡単です:
gem をインストールして require します。
a = Whois.whois("google.com")
a.利用可能ですか? =>偽
Ruby gems 経由でインストールする場合は、CLI もバンドルされています: ruby-whois
ウェブページ: ruby-whois.org
次のように nslookup にシェルアウトできます。
`nslookup #{domain}`
結果を正規表現などを使用してテキストとして解析します。
または、 Socketクラス、具体的には Socket.getaddrinfoを使用できます。この質問については、以前のStackOverflow の回答を参照してください。