Skip to content

Resolve ip adresses to country code or range info

License

Notifications You must be signed in to change notification settings

pieterD7/ip2range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ip2Range

What is Ip2Range?

Ip2Range creates or queries a mysql database mapping ipV4 addresses to countries with the option of overriding the country code by ranges in cidr notation. For example the ip address of google-bot becomes 'google-bot' instead of 'us'. You are free to enter other ranges.

Installation

   $ composer install

   $ php ip2range.php

   $ nano ip2range.ini

Usage

Configuration of ip2range.php can be changed by editing the iniFile. The stem of the programme name is used determining the default iniFile name.

Ip2range.php can be called with input from a pipe and to create an ip address information table.

Create ip ranges database

If a database is given in an iniFile a table with ip ranges can be built from ftp registries of ip address ranges assigned to countries.

   $ php ip2range.php -b

Or with a logfile:

   $ php ip2range.php -b -l logfile -d DEBUG &

   $ tail -f logfile

Instead of ftp the database can be created using the zip file from ip2nation.com. This database cannot be used for inserting a cidr to.

   $ php ip2range.php -z

Insert cidrs from assets/

Name will be derived from filename.

   $ php ip2range.php -c

Lookup an ip address

   $ php ip2range.php -ip 104.132.0.1

   A googlebot

Extend Apache2 log file

   $ cat access.log | php ip2range.php Line endings in piped input work only in php < 6

As CustomLog in httpd.conf

CustomLog "|/usr/bin/php /home/pi/ip2range/ip2range.php -out ${APACHE_LOG_DIR}/extended_access.log" combined

Warning and error messages are put to stderr and will be visible in httpd error log file.

About

Resolve ip adresses to country code or range info

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages