From 06e5ceb395d62e0465be7590a54273bce87a1170 Mon Sep 17 00:00:00 2001 From: Cristian Barrientos Beltran Date: Thu, 2 Jun 2016 19:21:07 +0200 Subject: [PATCH 1/2] isPublicIP first commit --- NAMESPACE | 1 + R/net.tools.R | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 20419f7..e4680a0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,3 +5,4 @@ export(whatismyip) export(hasIPformat) export(getIPaddress) export(freegeoip) +export(isPublicIP) diff --git a/R/net.tools.R b/R/net.tools.R index bd4cfc2..3199b9f 100644 --- a/R/net.tools.R +++ b/R/net.tools.R @@ -127,4 +127,26 @@ freegeoip <- function(ip, format = ifelse(length(ip) == 1,'list','dataframe')) { } return(ret) } -} +} + +#' isPublicIP +#' Returns TRUE for Public IP and returns FALSE for Private IP +#' +#' @param ip +#' +#' @return +#' Boolean +#' @export +#' +#' @examples +#' ip <- "0.0.0.0" (Public IP) returns TRUE +#' ip <- "10.0.0.0" (Private IP) returns FALSE +isPublicIP <- function(ip) { + + longIP <- ip2long(ip) + return(ifelse(longIP < 167772160 || + (longIP > 184549375 && longIP < 2851995648) || + (longIP > 2852061183 && longIP < 2886729728) || + (longIP > 2887778303 && longIP < 3232235520) || + (longIP > 3232301055), "TRUE", "FALSE")) +} From af1161738b111f058147ff9764f7d188eb31f487 Mon Sep 17 00:00:00 2001 From: Cristian Barrientos Beltran Date: Thu, 2 Jun 2016 20:46:11 +0200 Subject: [PATCH 2/2] "file to copy tests from, for isPublicIP" --- tests/testIsPublicIP.R | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/testIsPublicIP.R diff --git a/tests/testIsPublicIP.R b/tests/testIsPublicIP.R new file mode 100644 index 0000000..a487578 --- /dev/null +++ b/tests/testIsPublicIP.R @@ -0,0 +1,36 @@ +#Testing isPublicIP + +#Primer rango de IPs publicas +test1 <- "0.0.0.0" +test2 <- "9.255.255.255" + +#Primer rango de IPs privadas +test3 <- "10.0.0.0" +test4 <- "10.255.255.255" + +#Segundo rango de IPs publicas +test5 <- "11.0.0.0" +test6 <- "169.253.255.255" + +#Segundo rango de IPs privadas +test7 <- "169.254.0.0" +test8 <- "169.254.255.255" + +#Tercer rango de IPs publicas +test5 <- "169.255.0.0" +test6 <- "172.15.255.255" + +#Tercer rango de IPs privadas +test7 <- "172.16.0.0" +test8 <- "172.31.255.255" + +#Cuarto rango de IPs publicas +test9 <- "172.32.0.0" +test10 <- "192.167.255.255" + +#Cuarto rango de IPs privadas +test11 <- "192.168.0.0" +test12 <- "192.168.255.255" + +#Quinto rango de IPs publicas +test13 <- "192.169.0.0" #En adelante