13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/sane/socket_ips.rb', line 13
def get_ips hostname
begin
socket_info = Socket.getaddrinfo(hostname, nil,
Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil,
Socket::AI_CANONNAME).select{|type| type[0] == 'AF_INET'}
raise if socket_info.length == 0
ips = socket_info.map{|info| info[3]}
return ips
rescue => e
begin
ipInt = gethostbyname(hostname)[3]
return ["%d.%d.%d.%d" % [ipInt[0].ord, ipInt[1].ord, ipInt[2].ord, ipInt[3].ord]]
rescue SocketError
return nil
end
end
end
|