A micro-package for getting your IP address, either the local/internal or the public/external one. Currently only IPv4 addresses are supported.
You can install the stable version from CRAN using the usual `install.packages()
install.packages("getip")
The development version is maintained on GitHub:
::install_github("wrathematics/getip") remotes
To get your local (internal) IP address:
::getip("internal") getip
To get your public (external) IP address:
::getip("external") getip
The argument is case-insensitive and operates by partial matching. So
if you’re very lazy, you can just type getip("e")
for the
external IP.
There are two other exported helper functions. One is
validip()
which will check if a vector of strings are
potentially valid IP addresses (though not necessarily in active use —
i.e., it does not use the internet)
= c("127.0.0.1", "25", "255.255.255.255", "255.555.255.1")
ips ::validip(ips)
getip## [1] TRUE FALSE TRUE FALSE
The final exported function is hostname2ip()
. This
returns a list of vectors of IP addresses for a vector of hostnames.
This queries the internet.
= c("www.google.com", "localhost", "www.yahoo.com")
hosts ::hostname2ip(hosts)
getip## [[1]]
## [1] "64.233.185.103" "64.233.185.99" "64.233.185.147" "64.233.185.106"
## [5] "64.233.185.105" "64.233.185.104"
##
## [[2]]
## [1] "127.0.0.1" "127.0.0.1"
##
## [[3]]
## [1] "74.6.231.21" "74.6.231.20" "74.6.143.26" "74.6.143.25"