So this is an article to serve as documentation for one of the data sources available to download for FREE from this site.
It's useful to have a CSV list of all the IP ranges and their allocated country. Our use here was to create a refreshable country by IP address list that we can use when parsing our website logs to check where visitors were from.
Note: we also use and love Advanced Web Statistics (awstats) but this was so that you could have your own country lookup script.
Should contain the following:
- create_countriesipranges_table.sql: SQL to create a pre-populated table into a MySQL database.
- iana_ipv4_address_space_registry.csv: comma separated values list of all countries, regions and their respective IP ranges.
- ip_lookup.php: to use the database
- License.txt: Released under GNU/GPL
I wanted my own IP lookup script to tell me the country that is allocated a given IP address, this is what I use.
The scripts in the folder you have downloaded are to create a lookup function using a MySQL database and a PHP script. As well as a CSV file equivalent.
How to use:
- Download from my site: «Download»
- Run the SQL script against a test database,
- Modify the table name to use if necessary.
- Uncomment the drop statement if running for the second time.
- Modify the PHP file to use database login credentials,
- $db_host = "localhost"; // Database host name
- $db_user = "my_database_user"; // User for database authentication
- $db_pass = "my_database_password"; // Password for database authentication
- $db_name = "my_database"; // Database name
- $db_table = "mytable_countryipranges";// Database table
- Upload the PHP file to your website
- Test by using a web browser to visit: http://www.mysite.com/ip_lookup.php?ipv4=22.214.171.124 where www.mysite.com is your website where you uploaded this script. // should return China
Any questions, suggestions?
We are looking to add the ability to generate this data using other sources and in time a region by IP for more accuracy.
Feel free to feedback. It's FREE to download unlike others which is probably why I made the generator in the first place but I do like to make people sign up so I can gauge the level of interest.