Method: Rex::Socket.gethostbyname

Defined in:
lib/rex/socket.rb

.gethostbyname(host) ⇒ Object

Wrapper for Socket.gethostbyname which takes into account whether or not an IP address is supplied. If it is, then reverse DNS resolution does not occur. This is done in order to prevent delays, such as would occur on Windows.



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/rex/socket.rb', line 212

def self.gethostbyname(host)
  if (is_ipv4?(host))
    return [ host, [], 2, host.split('.').map{ |c| c.to_i }.pack("C4") ]
  end

  if is_ipv6?(host)
    # pop off the scopeid since gethostbyname isn't smart enough to
    # deal with it.
    host, _ = host.split('%', 2)
  end

  ::Socket.gethostbyname(host)
end