我有以下代码:
#!/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
很好,但是当我输入一个不反转的 IP 地址时,我收到异常错误:
i.rb:8:in `gethostbyaddr': host not found (SocketError)
from i.rb:8
如何隐藏消息?谢谢!