Learn R Programming

ipaddress (version 0.2.0)

hostname: Translate address to/from hostname

Description

as_hostname() performs reverse DNS resolution (translating IP addresses to hostnames)

from_hostname() performs forward DNS resolution (translating hostnames to IP addresses)

Usage

as_hostname(ip, multiple = FALSE)

from_hostname(host, multiple = FALSE)

Arguments

ip

An ip_address vector

multiple

A logical scalar indicating if all resolved endpoints are returned, or just the first endpoint (the default). This determines whether a vector or list of vectors is returned.

host

A character vector of hostnames

Value

  • as_hostname() returns a character vector or a list of character vectors (depending upon the multiple argument)

  • from_hostname() returns a ip_address vector or a list of ip_address vectors (depending upon the multiple argument)

Details

These functions require an internet connection. Before processing the input vector, we first check that a known hostname can be resolved. If this fails, an error is raised.

If DNS lookup cannot resolve an input, then NA is returned for that input. If an error occurs during DNS lookup, then a warning is emitted and NA is returned for that input.

DNS resolution performs a many-to-many mapping between IP addresses and hostnames. For this reason, these two functions can potentially return multiple values for each element of the input vector. The multiple argument control whether all values are returned (a vector for each input), or just the first value (a scalar for each input).

See Also

The base function nsl() provides forward DNS resolution to IPv4 addresses, but only on Unix-like systems.

Examples

Run this code
# NOT RUN {
from_hostname("r-project.org")

as_hostname(from_hostname("r-project.org"))
# }

Run the code above in your browser using DataLab