Ruby/Network/IP Address
Материал из Wiki.crossplatform.ru
Содержание |
Get all the addresses associated with a hostname
require "resolv" Resolv.each_address("http://www.google.ru/") do |ip| puts ip end
resolv useful for converting between hostnames and IP addresses
require "resolv" puts Resolv.getaddress("http://www.google.ru/")
To search for MX records you have to use the Resolv::DNS class
require "resolv" Resolv::DNS.open do |dns| mail_servers = dns.getresources("google.ru", Resolv::DNS::Resource::IN::MX) mail_servers.each do |server| puts "#{server.exchange.to_s} - #{server.preference}" end end
turn IP addresses into hostnames using the getname method
require "resolv" ip = "192.0.34.166" begin puts Resolv.getname(ip) rescue puts "No hostname associated with #{ip}" end