gethostinfo()
Returns the hostname or IP address of a host.
Syntax
Parameter
Parameter | Definition |
---|---|
host | Host name (fully qualified with domain, or relative distinct without domain) or IP address (IPv4 or IPv6) of the host |
Description
This function is similar to the C language gethostbyname()/gethostbyaddr() functions. Given a host name or IP address the function will obtain the official host name, aliases and IP addresses associated with the machine. This function supports IPv6.
The first line is a comma separated list of names. The first name is the official host name, the following names are the aliases. The second line is a comma-separated list of IP addresses associated with the machine.
On a dual stack hosts, both the IPv4 and IPv6 addresses are returned.
On error, the empty string is returned. An error indicates that the name/IP address could not be found. The PSL errno variable is not set by this function.
Example
The first examples uses a IPv4 address.
web = gethostinfo("www.google.com");
print("The host information for loopback 127.0.0.1 is:\n");
print(loc . "\n");
print("The host information for www.google.com is:\n");
print(web . "\n");
The example above returns the following:
venier
127.0.0.1
The host information for www.google.com is:
www.google.akadns.net,www.google.com
64.233.167.99,64.233.167.104
The following example uses an IPv6 address.
host = gethostinfo("punperfms058");
web = gethostinfo("www.google.com");
print("The host information for 2001:500:100:1100:5993:180e:8da5:78ec
is:\n");
print(loc . "\n");
print("The IPaddress for punperfms058 host is:\n");
print(host . "\n");
print("The host information for www.google.com is:\n");
print(web . "\n");
The example above returns the following:
punperfms058
2001:500:100:1100:5993:180e:8da5:78ec
The IPaddress for punperfms058 host is:
punperfms058
2001:500:100:1100:5993:180e:8da5:78ec
The host information for www.google.com is:
www.l.google.com
74.125.235.20,74.125.235.16,74.125.235.17,74.125.235.18,74.125.235.19