compare the ip address of different hostnames
Jul 20
2007
2007
Comments Off
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