172:rp young$ cat iptodns.rb
#!/usr/bin/env ruby
require 'resolv'
def check
if ARGV[0] == nil
abort 'Please input ARGV[0]'
end
end
check
def ipdcheck
begin
puts Resolv.getname(ARGV[0])
rescue
puts "No hostname associated with #{ARGV[0]}"
end
end
ipdcheck
Example)
172:rp young$ ruby iptodns.rb 202.131.30.12
No hostname associated with 202.131.30.12
172:rp young$ ruby iptodns.rb 127.0.0.1
localhost
172:rp young$ ruby iptodns.rb 192.0.34.166
34-166.lax.icann.org
172:rp young$