compare the ip address of different hostnames

Jul 20
2007
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

Comments are closed.

Calendar

July 2007
M T W T F S S
    Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Tags