IP2Proxy Varnish Module
An Varnish module that enables the user to find the country, region, city, ISP and proxy information by IP address. The module reads the proxy information from IP2Proxy BIN data file.
This module currently only support Varnish version 6.2.
Required IP2Proxy C Library to work.
Before install and use this module, you have to install:
- IP2Proxy C Library. You can get IP2Proxy C Library from https://github.com/ip2location/ip2proxy-c .
- varnishapi (varnish-dev) package. install varnishapi package by running this command:
apt-get install varnish-dev
- autoconf, libtool and make. Those packages will be needed during compilation and installation process.
- And of course, the Varnish.
Then, clone this repo into your local, and run following commands to install:
./autogen.sh ./configure make make install
First, import this module like this:
After that, initialize and load the database you downloaded from IP2Location like this:
Finally, called our module functions with IP address. For example:
set req.http.X-Country-Code = ip2proxy.country_short("client.ip"); set req.http.X-Region = ip2proxy.region("client.ip");
The table below listed down the functionality of available functions. For more information on returned data from IP2Location BIN database file, visit here: https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen
Initialize and load database. The first argument indicates the path of the database, and the second argument indicates the mode used to open the database. Modes available are: IP2PROXY_FILE_IO, IP2PROXY_SHARED_MEMORY and IP2PROXY_CACHE_MEMORY.
Check wether if an IP address was a proxy. Returned value:
- -1 : errors
- 0 : not a proxy
- 1 : a proxy
- 2 : a data center IP address
set req.http.X-Is-Proxy = ip2proxy.is_proxy("client.ip");
Return the proxy type. Please visit IP2Location for the list of proxy types supported.
set req.http.X-Proxy-Type = ip2proxy.proxy_type("client.ip");
Returns two-letter country code based on ISO 3166.
set req.http.X-Country-Code = ip2proxy.country_short("client.ip");
Returns country name based on ISO 3166.
set req.http.X-Country-Name = ip2proxy.country_long("client.ip");
Returns region or state name.
set req.http.X-Region = ip2proxy.region("client.ip");
Returns city name.
set req.http.X-City = ip2proxy.city("client.ip");
Returns Internet Service Provider or company's name of the IP Address.
set req.http.X-ISP = ip2proxy.isp("client.ip");
Returns Internet domain name associated with IP address range.
set req.http.X-Domain = ip2proxy.domain("client.ip");
Returns Usage type classification of ISP or company.
set req.http.X-Usagetype = ip2proxy.usagetype("client.ip");
Return autonomous system number (ASN).
set req.http.X-Usagetype = ip2proxy.asn("client.ip");
Return autonomous system (AS) name.
set req.http.X-Usagetype = ip2proxy.as("client.ip");
Returns proxy last seen in days.
set req.http.X-Usagetype = ip2proxy.last_seen("client.ip");
- "Where can I get the database to use?"
- "I can't install the module. Please help me."
Answer: Once again, before you install the package, please make sure that you have installed autoconf, libtool and make packages first. Those packages are necessary to compile and install this module.
- "Why am I getting an error message said that Package varnishapi was not found?"
Answer: In order to use Varnish vmod, you have to install varnishapi package before hand. Please refer to the Installation section first before install this module.
- "I am getting error message said that You need rst2man installed to make dist. What should I do?"
Answer: If you encounter such message, you can install rst2man by installing python-docutils package than provide rst2man:
apt-get install python-docutils
- "I am getting Permission denied when running autogen.sh.. What should I do?"
Answer: You can try to edit the permission for autogen.sh by:
chmod +x autogen.sh