GithubHelp home page GithubHelp logo

ip2location / ip2proxy-varnish Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 23 KB

To detect proxy servers with country, region, city, ISP and proxy type information using IP2Proxy binary database.

License: Other

Makefile 15.46% Shell 24.71% M4 19.11% C 40.72%
ip2proxy ip2proxy-varnish ip2location proxy-information proxy-database varnish geolocation

ip2proxy-varnish's Introduction

IP2Proxy Varnish Module

Author: IP2Location
Date: 2020-11-24
Version: 1.2.0
Manual section: 3

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.

Installation

Before install and use this module, you have to install:

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

Usage

First, import this module like this:

import ip2proxy;

After that, initialize and load the database you downloaded from IP2Location like this:

ip2proxy.init_db("path_to_database", "IP2PROXY_FILE_IO");

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");

Functions

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

init_db

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.

Example

ip2proxy.init_db("path_to_database", "IP2LOCATION_FILE_IO");

is_proxy

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

Example

set req.http.X-Is-Proxy = ip2proxy.is_proxy("client.ip");

proxy_type

Return the proxy type. Please visit IP2Location for the list of proxy types supported.

Example

set req.http.X-Proxy-Type = ip2proxy.proxy_type("client.ip");

country_short

Returns two-letter country code based on ISO 3166.

Example

set req.http.X-Country-Code = ip2proxy.country_short("client.ip");

country_long

Returns country name based on ISO 3166.

Example

set req.http.X-Country-Name = ip2proxy.country_long("client.ip");

region

Returns region or state name.

Example

set req.http.X-Region = ip2proxy.region("client.ip");

city

Returns city name.

Example

set req.http.X-City = ip2proxy.city("client.ip");

isp

Returns Internet Service Provider or company's name of the IP Address.

Example

set req.http.X-ISP = ip2proxy.isp("client.ip");

domain

Returns Internet domain name associated with IP address range.

Example

set req.http.X-Domain = ip2proxy.domain("client.ip");

usage_type

Returns Usage type classification of ISP or company.

Example

set req.http.X-Usagetype = ip2proxy.usagetype("client.ip");

asn

Return autonomous system number (ASN).

Example

set req.http.X-Usagetype = ip2proxy.asn("client.ip");

as

Return autonomous system (AS) name.

Example

set req.http.X-Usagetype = ip2proxy.as("client.ip");

last_seen

Returns proxy last seen in days.

Example

set req.http.X-Usagetype = ip2proxy.last_seen("client.ip");

threat

Return security threat reported for this IP.

Example

set req.http.X-Threat = ip2proxy.threat("client.ip");

FAQ

  1. "Where can I get the database to use?"

Answer: You can get free IP2Proxy LITE databases from https://lite.ip2location.com, or purchase an IP2Proxy commercial database from https://www.ip2location.com/database/ip2proxy.

  1. "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.

  2. "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.

  3. "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
    
  4. "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
    

Support

Email: [email protected]. URL: https://www.ip2location.com

ip2proxy-varnish's People

Contributors

ip2location avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gquintard zi0r

ip2proxy-varnish's Issues

Error: unused variable ‘mtype’

Hello,
Ip2proxy-varnish does not compile - error: mtype storage size unknown.
Below are some details.

Thank you in advance.

/tmp/ip2proxy-varnish-master# sh autogen.sh 
Detected IP2Proxy C Library.
+ libtoolize --copy --force
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
+ aclocal -I m4 -I /usr/share/aclocal
+ autoheader
+ automake --add-missing --copy --foreign
configure.ac:12: installing './compile'
configure.ac:10: installing './missing'
src/Makefile.am: installing './depcomp'
+ autoconf


/tmp/ip2proxy-varnish-master# ./configure 
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for gcc option to accept ISO C99... none needed
checking for gcc option to accept ISO Standard C... (cached) none needed
checking how to run the C preprocessor... gcc -E
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether make sets $(MAKE)... (cached) yes
checking for rst2man... rst2man
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for ANSI C header files... (cached) yes
checking sys/stdlib.h usability... no
checking sys/stdlib.h presence... no
checking for sys/stdlib.h... no
checking for python3... python3
checking vsha256.h usability... yes
checking vsha256.h presence... yes
checking for vsha256.h... yes
checking cache/cache.h usability... yes
checking cache/cache.h presence... yes
checking for cache/cache.h... yes
checking for python3.9... (cached) python3
checking for varnishtest... /usr/bin/varnishtest
checking for varnishd... /usr/sbin/varnishd
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands


/tmp/ip2proxy-varnish-master# make
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /tmp/ip2proxy-varnish-master/missing autoheader)
rm -f stamp-h1
touch config.h.in
cd . && /bin/bash ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
make  all-recursive
make[1]: Entering directory '/tmp/ip2proxy-varnish-master'
Making all in src
make[2]: Entering directory '/tmp/ip2proxy-varnish-master/src'
/bin/bash ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..  -I/usr/include/varnish  -Wall -Wextra -Werror -g -O2 -MT vmod_ip2proxy.lo -MD -MP -MF .deps/vmod_ip2proxy.Tpo -c -o vmod_ip2proxy.lo vmod_ip2proxy.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/varnish -Wall -Wextra -Werror -g -O2 -MT vmod_ip2proxy.lo -MD -MP -MF .deps/vmod_ip2proxy.Tpo -c vmod_ip2proxy.c  -fPIC -DPIC -o .libs/vmod_ip2proxy.o
vmod_ip2proxy.c: In function ‘vmod_init_db’:
vmod_ip2proxy.c:36:25: error: storage size of ‘mtype’ isn’t known
  enum IP2Proxy_mem_type mtype;
                         ^~~~~
vmod_ip2proxy.c:36:25: error: unused variable ‘mtype’ [-Werror=unused-variable]
cc1: all warnings being treated as errors
Makefile:447: recipe for target 'vmod_ip2proxy.lo' failed
make[2]: *** [vmod_ip2proxy.lo] Error 1
make[2]: Leaving directory '/tmp/ip2proxy-varnish-master/src'
Makefile:514: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/ip2proxy-varnish-master'
Makefile:382: recipe for target 'all' failed
make: *** [all] Error 2


Trying to compile with varnish version 6.2.3

varnishd -V
varnishd (varnish-6.2.3 revision 84d239c93e756ae255b6abb459c1052a36a409e9)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.