compare the ip address of different hostnames

Posted by root Fri, 20 Jul 2007 10:38:00 GMT


require "socket"

unless ARGV.size == 2
 raise ArgumentError,
   "Expected two hostnames, got #{ARGV.size}"
end

h1,h2 = ARGV

begin
  h1,h2 = Socket::getaddrinfo(h1, 7)[0][3], Socket::getaddrinfo(h2, 7)[0][3]
rescue
  print "#{$!}...\texiting\n"
  exit
end

if h1.eql? h2
  puts "hosts have the same ip address: #{h1}"
else
  puts "hosts differ: #{h1} #{h2}"
end

Posted in  | Tags ,  | no comments