net.resolve(hostname, [family])function

Resolves the given hostname to an IP address from the DNS record.

Parameters

hostname

The string to indicate the hostname to resolve, for example "luart.org".

[family]

An optional string to indicate the IP address family to retrieve from the DNS record :

  • "ipv4" : an IPv4 address will be returned (default)
  • "ipv6" : an IPv6 address will be returned

Return value

  • In case of success, returns the IP address associated with the DNS record, represented by a string.
  • If no DNS record was found, returns nil
  • In case of error, returns false (you can check error message with the net.error property).

Example

--! luart-extensions import console local net = require "net" console.write('Enter hostname : ') local ip = net.resolve(console.readln()) or "not found"; print('IP address associated with that hostname : '..ip)