Learn R Programming

IP (version 0.1)

Hostinfo: host-info

Description

Methods for querying information about hosts (DNS) or IP (address spaces)

Usage


  host(host,…)
  
  host(host,…)
  
  host.info(host,…)
  
  localhost.ip(…)
  
  toIdna(domain, flags)
  
  fromIdna(domain, flags)
  
  fqdn(hostname) 
  
  is.fqdn(hostname)
  
  whois(domain, referer , output, verbose)
  
  rir.names() 
  
  ipv4.rir() 
  
  ipv6.rir() 
  
  ipv4.addr.space()  
  
  ipv6.addr.space()
  
  ipv4.reserved()
  
  ipv6.reserved()
  
  ipv4.recovered()
  
  ipv6.unicast()

Arguments

host

a vector of either or IPv4, IPv6, IP addresses

further arguments. Only host.info (default:FALSE) for host() at the moment

hostname

A character vector of host names

domain

A character vector of domain names

flags

Flags for IDNA conversion. "IDNA_DEFAULT": default behavior, "IDNA_ALLOW_UNASSIGNED": allow processing of unassigned Unicode code points, "IDNA_USE_STD3_ASCII_RULES": check output to make sure it is a STD3 conforming host name.

referer

An optional referrer to be queried

output

An integer specifying whether to returns the raw response from the referrer (0) or a parsed key-value named vector (1). The latter is still experimental due to the heterogeneity of responses.

verbose

An integer specifying the level of verbosity

Value

host

an host object or a character vector

%%
host.info

a character vector

%%
localhost.ip

an IP

Details

Methods et functions for querying informations about hosts

  • host() takes a character vector of domain names as arguments for DNS lookup. Addresses can be extracted with the corresponding methods (ipv4(), ipv6(), ip()). Also takes either IPv4, IPv6 or IP objects for reverse DNS lookup and returns the corresponding domain name (or NA if not found).

  • host.info() (depreciated) takes either IPv4, IPv6 or IP objects for reverse DNS lookup and returns the corresponding domain name (or NA if not found)

  • localhost.ip() retrieves the host's interfaces IP adresses

  • fqdn() extracts the fully qualified name of a domain name, -eg to query whois databases

  • is.fqdn() tests whether strings in a character vector qualify as fully qualified names

  • whois() queries whois databases for a vector of fully qualified domain names.

Since localhost.ip() needs OS specific system call ---as well as host() and host.info()---, this function is only available for POSIX compliant OS at the moment. Support of Internationalized Domain Names (IDN) also depends on the system's libraries. For instance, glibc supports IDN starting with version 2.3.4. Use the toIdna() function to ensure proper domain names encoding. In addition, the host() and host.info() methods are still very experimental and might change in the future.

whois databases typically contain information such as registrars' names … Note that responses are not standardized at all and may require an ad hoc parser. This is why the whois() function returns either a (still buggy at the moment) named vector of key-value pairs or the raw responses from the referrers. The relevant referrer url can be determined automatically (default) or passed as an argument.

Functions returning IP addresses assignments from IANA registries

  • ipv4.addr.space() and ipv6.addr.space() : return the corresponding IP address space

  • ipv4.reserved() and ipv6.reserved() : return the corresponding IP reserved address space

  • ipv6.unicast() : IPv6 unicast addresses

  • ipv4.recovered() : pool of IPv4 addresses recovered by IANA from RIRs

  • ipv4.rir() and ipv6.rir() : returns the RIRs IP address spaces

  • rir.names() : Regional Internet Registry names

The IP address spaces is divided into many ranges with specific purposes. For instance, IP addresses can be assigned to organizations. Some addresses are otherwise reserved for special purposes such as loopback, subnetting, local communications within a private network, multicasting, broadcasting,… The IP address space is managed globally by the Internet Assigned Numbers Authority (IANA), and locally by five regional Internet registries (RIRs) :
  • The African Network Information Center (AFRINIC) serves Africa

  • The American Registry for Internet Numbers (ARIN) serves Antarctica, Canada, parts of the Caribbean, and the United States

  • The Asia-Pacific Network Information Centre (APNIC) serves East Asia, Oceania, South Asia, and Southeast Asia

  • The Latin America and Caribbean Network Information Centre (LACNIC) serves most of the Caribbean and all of Latin America

  • The R<U+00E9>seaux IP Europ<U+00E9>ens Network Coordination Centre (RIPE NCC) serves Europe, Central Asia, Russia, and West Asia

RIRs are responsible in their designated territories for assignment to end users and local Internet registries, such as Internet service providers.

Note differences in ouptut between ipv4.addr.space() and ipv6.addr.space(). RIRs IPv4 and Ipv6 assignments are stored by IANA in tables with different naming scheme (corresponding to ipv4.addr.space() and ipv6.unicast()). In the early days of IPv4 deployment, addresses were assigned directly to end user organizations. Therefore, ipv4.addr.space() also mixes RIR and end user organizations assignments. To find the corresponding RIR, use ipv4.rir() and ipv6.rir() instead. Also note that some lookups may be misleading because some IPv4 ranges have been transferred from one RIR to an another (see example). For instance, some address ranges were assigned by ARIN in the 80's to European organizations such as universities before RIPE-NCC began its operations in 1992. Those ranges were later transferred to the RIPE NCC but still belong to the ARIN address space. Likewise, some IPv4 addresses have been recovered by IANA from RIRs in order to delay IPv4 pool exhaustion and were later reassigned to other RIRs (see ipv4.recovered).

Examples

Run this code
# NOT RUN {
##
# }
# NOT RUN {
host(
  ipv4(
    c("127.0.0.1")
  )
)
# }
# NOT RUN {
##
h <- host(c(
  "icann.org", "iana.org"
))
##
host(ipv4(h))
##
## Domain names internationalization
##
##
## results may vary according to the (POSIX) platform
host(c("bucher.de", "B<U+00FC>cher.de"))
## 
dn <- c( 
  enc2utf8("b<U+00FC>cher.de") ## ensure UTF-8
  ## cannot input emoji with Latex and "\u1f4a9" does not work either in R
  , rawToChar(as.raw(c(0xf0, 0x9f, 0x92, 0xa9, 0x2e, 0x6c, 0x61)))
)
##
Encoding(dn) <- "UTF-8"
##
dn
## enforce internationalization with different options
flags <-rep( c( "IDNA_DEFAULT" , "IDNA_ALLOW_UNASSIGNED"), each = length(dn))
##
dni <- toIdna( dn, flags)
##
host(dni)
# }
# NOT RUN {
## French country-code top-level domains (ccTLD)
tld <- whois(
  c(
    "fr", "re", "tf", "wf", "pm", "yt"
    , "nc", "mq"##, "gp", "gf"
    , "pf"
  )
  , verbose = 1
  , output = 0
)
##
sapply(tld, function(x)names(x))
# }
# NOT RUN {
##
##
##
rhost     <- host('r-project.org')
## hostname       : "cran.wu-wien.ac.at"
rhost.hnm <- host.info(ipv4(rhost))
## primary domain : "ac.at"
fqdn(rhost.hnm)
## ARIN 
ipv4.rir()[ip.match(ipv4(rhost), ipv4.rir())]
##
ip.match(ipv4(rhost), ipv4.recovered())
## domain name info 
rdom.wh   <- whois('r-project.org', output=1)
## "AT"
rdom.wh[['r-project.org']]['Registrant Country']
## host
rhost.wh0 <- whois(ipv4(rhost),verbose = 2, output=1)
# }

Run the code above in your browser using DataLab