iptools 0.3.0 (“Violet Packet”) Now on CRAN with Windows Support!

January 8, 2016

(This article was first published on R – rud.is, and kindly contributed to R-bloggers)

iptools is a set of tools for working with IP addresses. Not just work, but work fast. It’s backed by Rcpp and now uses the AsioHeaders package by Dirk Eddelbuettel, which means it no longer needs to link against the monolithic Boost libraries and works on Windows!

What can you do with it? One thing you can do is take a vector of domain names and turn them into IP addresses:

hostname_to_ip(c("rud.is", "dds.ec", "ironholds.org", "google.com"))
## [[1]]
## [1] ""
## [[2]]
## [1] ""
## [[3]]
## [1] ""
## [[4]]
##  [1] "2607:f8b0:400b:80a::100e" ""           ""          
##  [4] ""           ""            ""          
##  [7] ""            ""           ""          
## [10] ""            ""            ""

That means you can pump a bunch of domain names from logs into iptools and get current IP address allocations out for them.

You can also do the reverse:

hostname_to_ip(c("rud.is", "dds.ec", "ironholds.org", "google.com")) %>% 
  flatten_chr() %>% 
  ip_to_hostname() %>% 
##  [1] ""           "dds.ec"                    ""            
##  [4] "yyz08s13-in-x0e.1e100.net" "yyz08s13-in-f5.1e100.net"  "yyz08s13-in-f6.1e100.net" 
##  [7] "yyz08s13-in-f4.1e100.net"  "yyz08s13-in-f0.1e100.net"  "yyz08s13-in-f8.1e100.net" 
## [10] "yyz08s13-in-f3.1e100.net"  "yyz08s13-in-f7.1e100.net"  "yyz08s13-in-f9.1e100.net" 
## [13] "yyz08s13-in-f2.1e100.net"  "yyz08s13-in-f1.1e100.net"  "yyz08s13-in-f14.1e100.net"

Notice that it handled IPv6 addresses and also cases where no reverse mapping existed for an IP address.

You can convert IPv4 addresses to and from long integer format (the 4 octet version of IPv4 addresses is primarily to make them easier for humans to grok), generate random IP addresses for testing, test IP addresses for validity and type and also reference data sets with registered assignments (so you can see allocated IP groups). Plus, it includes xff_extract() which can help identify an actual IP address (helpful when connections come from behind proxies).

We can’t thank Dirk enough for cranking out AsioHeaders since it means there will be many more network/”cyber” packages coming for R and available on every platform.

You can find iptools version 0.3.0 on CRAN now (it may take your mirror a bit to catch up), grab the source release on GitHub or check out the repo, poke around, submit issues and/or contribute!

Isn’t it great when an R package can help you with resolutions in the new year?

To leave a comment for the author, please follow the link and comment on their blog: R – rud.is.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)