How to use IP2Proxy in R language?

How to use the latest IP2Proxy R package

R is a programming language that is widely used in statistical computing. It was created by Ross Ihaka and Robert Gentleman back in year 1993. Many developers had created external packages in order to extend the function in R. These packages can help users on processing and understanding the data. For example, user can use a proxy detection package to query the proxy information and then identify whether the IP address is a proxy or not.

In this article, we are going to guide you on how to use IP2Proxy in R. You will learn how to use the IP2Proxy R package and the IP2Proxy BIN database to query the proxy information of an IP address.

Prerequisite

IP2Location R package leverage the IP2Proxy Python library for proxy information lookup. Hence, you will need to install the Python and IP2Proxy Python module before using this R package. To install IP2Proxy Python module, you can use the following command: pip install IP2Proxy

Before getting started, you are required to download and install the following components:

IP2Location LITE database

Installation

To install IP2Proxy R package, you can just type the following command in your R console:

install.packages(ip2proxy)

How to query proxy information?

  1. In your R console, import IP2Location BIN database by using ip2proxy::open. For example, ip2location::open(“full_path_to_IP2Proxy_BIN_database”)
  2. Query the geolocation information for an IP address by using ip2proxy::get_all. For example, ip2proxy::get_all("1.2.3.4")
  3. You will see the results like this:
$is_proxy
[1] 1

$proxy_type
[1] "PUB"

$country_short
[1] "AU"

$country_long
[1] "Australia"

$region
[1] "Queensland"

$city
[1] "Brisbane"

$isp
[1] "APNIC Pty Ltd"

$domain
[1] "apnic.net"

$usage_type
[1] "DCH"

$asn
[1] "-"

$as_name
[1] "-"

$last_seen
[1] "30"

$threat
[1] "SPAM"

$provider
[1] "-"

How to check whether an IP address is a proxy or not?

  1. In your R console, import IP2Location BIN database by using ip2proxy::open. For example, ip2location::open(“full_path_to_IP2Proxy_BIN_database”)
  2. Use ip2proxy::is_proxy function to check whether an IP address is a proxy or not. For example, ip2proxy::is_proxy("1.2.3.4")
  3. You will see the result like this:
$is_proxy
[1] 1

How to use IP2Proxy web service to query proxy information?

  1. Get your IP2Proxy web service API Key by purchasing the credits or request for a trial from here: https://www.ip2location.io
  2. In your R console, use the function ip2proxy::lookup_web_service to query the proxy information from the web service. For example, ip2proxy::lookup_web_service(your_api_key, '1.2.3.4', 'PX11')
  3. You will see the result like this:
$response
[1] "OK"

$countryCode
[1] "AU"

$countryName
[1] "Australia"

$regionName
[1] "Queensland"

$cityName
[1] "Brisbane"

$isp
[1] "APNIC Pty Ltd"

$domain
[1] "apnic.net"

$usageType
[1] "DCH"

$asn
[1] "0"

$as
[1] "-"

$lastSeen
[1] 30

$proxyType
[1] "PUB"

$threat
[1] "SPAM"

$provider
[1] "-"

$isProxy
[1] "YES"

$creditsConsumed
[1] 11

How to plot the IP address(es) on the map?

  1. In your R console, import IP2Proxy BIN database by using ip2proxy::open. For example, ip2proxy::open(“full_path_to_IP2Proxy_BIN_database”).
  2. We can then start to plot the IP addresses to the map by supplying a list of the IP addresses to a function called ip2proxy::plot_map() . For example, ip2proxy::plot_map(c('1.2.3.4','1.0.241.135')).
  3. You will see a map image like this:
    IP Address Map

Conclusion

Throughout this article, you would have learnt how to install and use the IP2Proxy R package to query for proxy information of an IP address. The proxy information obtained can help to identify whether the IP address poses a threat or not.


IP2Proxy Web Service

Explore the latest IP2Proxy Proxy Detection Web Service to retrieves proxy information.

Was this article helpful?

Related Articles