#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to deal with IP Address in R using the iptools package?
Description

To deal with IP address in R using the iptools package

Functions Used

ip_classify(ip_list) – To Validate an IP address and classify its type
ip_to_numeric(ip_list) – To convert the dotted decimal IP to numeric form
numeric_to_ip(ip_numeric) – To convert numeric form IP to dotted decimal IP
hostname_to_ip(hostname) – To convert the Host name to IP
ip_to_hostname(ip) – To convert IP to host name
range_boundaries() -To expand given IP address range
range_generate(range) – To generate ip address within a certain range
ip_in_range(ips, range) – To check whether the given ip address is in given range
ip_random(n) – To generate a valid IPv4 Address

Process

  Load the iptools package

  Load the IP address list

  Use the predefined functions to validate,handle the IP address

Sapmle Code

library(iptools)
ip_list=c(“192.168.23.35″,”255.236.20.188″,”259.152.25.36″,”1256.25.125.255″,”260b:12ff::1525:9d0b:2589:12ff”,”1234:2345:3456:4567:5678:45dc:2222:dcba”,”255:::::25fd::908f”,”102358:2555::4567:10000::::145d”)
#To Validate an IP address and classify its type
ip_classify(ip_list)
#To convert the dotted decimal IP address to numeric form
#Works with IPv4 addresses only
ip_list1=c(“163.25.250.36″,”255.255.255.255″,”240.115.235.0″,”10.5.2.3”)
ip_numeric=ip_to_numeric(ip_list1)
ip_to_numeric(ip_list1)
#To convert numeic form IP to dotted deciaml IP
numeric_to_ip(ip_numeric)
#To convert the Host name to ip
hostname_to_ip(“lga15s49-in-f6.1e100.net”)
#To convert IP to host name
ip_to_hostname(c(“172.217.5.6″,”216.239.32.6”))
#To expand the given IP ranges
#Produces a data.frame containing the smallest-valued and
#largest-valued IP addresses in that range
range_boundaries(c(“172.18.0.0/28″,”148.20.57.0/28″,”148.20.57.0/24”))
#To generate ip address within a certain range
range_generate(range = “192.168.53.0/28”)
#To check whether the given ip address is in given range
ips ip_in_range(ips, “148.20.57.0/28”)
#To generate a valid IPv4 Address
ip_random(n = 5)

Screenshots