To validate an IP address in R
require(MASS)
require(ggplot2)
require(scales)
require(gridExtra)
Load the IP Address
Split the IP address with the pattern \\.
Check for the required criteria of the splitted values
Verify the output
ip1=readline(prompt=”Enter the IP address : “)
strsplit(ip1,’\\.’)
y=0
x=as.integer(unlist(strsplit(ip1,’\\.’)))
if(length(x)==4)
{
for (i in (1:4))
{
if((x[i]>=0)&&(x[i]<256))
{
y=y+1
}
}
if(y==4)
{
cat(“\nValid IP Address”)
}else
{
cat(“Invalid IP Address”)
}
}else
{
cat(“\nInvalid Address”)
}