I have the following code:
#!/usr/bin/ruby
require 'socket'
server = '221.186.184.68'
if ( server =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ )
hostname = Socket.gethostbyaddr(server.split(".").map(&:to_i).pack("CCCC")).first
puts hostname
end
All well, but when I input an IP Address that doesn’t reverse I get exeception error:
i.rb:8:in `gethostbyaddr': host not found (SocketError)
from i.rb:8
How can I hide the message? Thanks!
use exception handling