PHPackages                             ip2location/ip2location-csv-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ip2location/ip2location-csv-converter

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ip2location/ip2location-csv-converter
=====================================

This PHP script converts IP2Location CSV database into IP range or CIDR format.

1.2.7(2y ago)3631114MITPHP

Since Jul 15Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/ip2location/ip2location-csv-converter)[ Packagist](https://packagist.org/packages/ip2location/ip2location-csv-converter)[ Docs](https://www.ip2location.com)[ RSS](/packages/ip2location-ip2location-csv-converter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (11)Used By (0)

IP2Location CSV Converter
=========================

[](#ip2location-csv-converter)

> **Note**: **For a more efficient and faster conversion process, we recommend using the [IP2Location Python CSV Converter](https://github.com/ip2location/ip2location-python-csv-converter)**

This PHP script converts IP2Location CSV data file, that contains the IP address in numeric notation, into dot-decimal notation (such as x.x.x.x) or CIDR notation (x.x.x.x/24). It supports both the IP2Location commercial edition, DB1 to DB24 database and also the free edition, IP2Location LITE database. In addition to this, this converter can also be used to convert any CSV file that contains the IP number (the numeric notation).

You can download the IP2Location CSV file at the below links:
[IP2Location Commercial Database](https://www.ip2location.com)
[IP2Location LITE Database](https://lite.ip2location.com)

Please do not use this script to convert IP2Location BIN data file. It only support the CSV format, not the binary format.

Installation
------------

[](#installation)

Please install this script using composer.

```
composer require ip2location/ip2location-csv-converter

```

After that, please copy the php script into the root directory of composer (the folder contains the composer.json and composer.lock files)

```
cp ./vendor/ip2location/ip2location-csv-converter/ip2location-csv-converter.php ./

```

Usage
-----

[](#usage)

```
php ip2location-csv-converter.php [-range | -cidr] [-replace | -append] INPUT_FILE OUTPUT_FILE
```

#### Parameters

[](#parameters)

ParameterDescription-rangeIP numbers will be converted into the first IP address and last IP address in the range.-cidrIP numbers will be converted into CIDR format.-hexIP numbers will be converted into hexadecimal format. (auto padding)-hex4IP numbers will be converted into hexadecimal format. (pad IPv4)-hex6IP numbers will be converted into hexadecimal format. (pad IPv6)-replaceThe IP numbers in will be replaced to the selected format.-appendThe converted format will be appended after the IP numbers field.### Example:

[](#example)

##### Sample Input

[](#sample-input)

```
"17170432","17301503","IN","India"
"17301504","17367039","CN","China"
"17367040","17432575","MY","Malaysia"
"17432576","17435135","CN","China"
"17435136","17435391","AU","Australia"
"17435392","17465343","CN","China"
"17465344","17498111","TH","Thailand"
"17498112","17563647","KR","Korea, Republic of"
"17563648","17825791","CN","China"
"17825792","17842175","KR","Korea, Republic of"

```

##### Convert into range with replace option:

[](#convert-into-range-with-replace-option)

Command:

```
php ip2location-csv-converter.php -range -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV

```

Output:

```
"1.6.0.0","1.7.255.255","IN","India"
"1.8.0.0","1.8.255.255","CN","China"
"1.9.0.0","1.9.255.255","MY","Malaysia"
"1.10.0.0","1.10.9.255","CN","China"
"1.10.10.0","1.10.10.255","AU","Australia"
"1.10.11.0","1.10.127.255","CN","China"
"1.10.128.0","1.10.255.255","TH","Thailand"
"1.11.0.0","1.11.255.255","KR","Korea, Republic of"
"1.12.0.0","1.15.255.255","CN","China"
"1.16.0.0","1.16.63.255","KR","Korea, Republic of"

```

##### Convert into CIDR with replace option:

[](#convert-into-cidr-with-replace-option)

Command:

```
php ip2location-csv-converter.php -cidr -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV

```

Output:

```
"1.6.0.0/15","IN","India"
"1.8.0.0/16","CN","China"
"1.9.0.0/16","MY","Malaysia"
"1.10.0.0/21","CN","China"
"1.10.8.0/23","CN","China"
"1.10.10.0/24","AU","Australia"
"1.10.11.0/24","CN","China"
"1.10.12.0/22","CN","China"
"1.10.16.0/20","CN","China"
"1.10.32.0/19","CN","China"

```

##### Convert into hexadecimal with replace option:

[](#convert-into-hexadecimal-with-replace-option)

Command:

```
php ip2location-csv-converter.php -hex -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV

```

Output:

```
"0000000001060000","000000000107ffff","IN","India"
"0000000001080000","000000000108ffff","CN","China"
"0000000001090000","000000000109ffff","MY","Malaysia"
"00000000010a0000","00000000010a09ff","CN","China"
"00000000010a0a00","00000000010a0aff","AU","Australia"
"00000000010a0b00","00000000010a7fff","CN","China"
"00000000010a8000","00000000010affff","TH","Thailand"
"00000000010b0000","00000000010bffff","KR","Korea, Republic of"
"00000000010c0000","00000000010fffff","CN","China"
"0000000001100000","0000000001103fff","KR","Korea, Republic of"

```

##### Convert into range with append option:

[](#convert-into-range-with-append-option)

Command:

```
php ip2location-csv-converter.php -range -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV

```

Output:

```
"17170432","17301503","1.6.0.0","1.7.255.255","IN","India"
"17301504","17367039","1.8.0.0","1.8.255.255","CN","China"
"17367040","17432575","1.9.0.0","1.9.255.255","MY","Malaysia"
"17432576","17435135","1.10.0.0","1.10.9.255","CN","China"
"17435136","17435391","1.10.10.0","1.10.10.255","AU","Australia"
"17435392","17465343","1.10.11.0","1.10.127.255","CN","China"
"17465344","17498111","1.10.128.0","1.10.255.255","TH","Thailand"
"17498112","17563647","1.11.0.0","1.11.255.255","KR","Korea, Republic of"
"17563648","17825791","1.12.0.0","1.15.255.255","CN","China"
"17825792","17842175","1.16.0.0","1.16.63.255","KR","Korea, Republic of"

```

##### Convert into CIDR with append option:

[](#convert-into-cidr-with-append-option)

Command:

```
php ip2location-csv-converter.php -cidr -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV

```

Output:

```
"17170432","17301503","1.6.0.0/15","IN","India"
"17301504","17367039","1.8.0.0/16","CN","China"
"17367040","17432575","1.9.0.0/16","MY","Malaysia"
"17432576","17435135","1.10.0.0/21","CN","China"
"17432576","17435135","1.10.8.0/23","CN","China"
"17435136","17435391","1.10.10.0/24","AU","Australia"
"17435392","17465343","1.10.11.0/24","CN","China"
"17435392","17465343","1.10.12.0/22","CN","China"
"17435392","17465343","1.10.16.0/20","CN","China"
"17435392","17465343","1.10.32.0/19","CN","China"
"17435392","17465343","1.10.64.0/18","CN","China"
"17465344","17498111","1.10.128.0/17","TH","Thailand"
"17498112","17563647","1.11.0.0/16","KR","Korea, Republic of"
"17563648","17825791","1.12.0.0/14","CN","China"
"17825792","17842175","1.16.0.0/18","KR","Korea, Republic of"

```

Custom Input File
-----------------

[](#custom-input-file)

You can use this converter for a custom input file provided the input is in CSV format, with the first and second field contain the **ip from** and **ip to** information in numeric format.

Support
-------

[](#support)

URL:

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance54

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~175 days

Recently: every ~2 days

Total

10

Last Release

911d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5fbe791b4a8d666a158043146d73380f05a0bea9062f0fa0852bf82f6bc762c?d=identicon)[ip2location](/maintainers/ip2location)

---

Top Contributors

[![ip2location-com](https://avatars.githubusercontent.com/u/6367210?v=4)](https://github.com/ip2location-com "ip2location-com (18 commits)")[![chrislim2888](https://avatars.githubusercontent.com/u/3418232?v=4)](https://github.com/chrislim2888 "chrislim2888 (6 commits)")

---

Tags

cidrcsv-convertercsv-formatgeolocationip-geolocationip-rangeip2locationphp-scriptgeolocationcsvconverterip2locationip2locationlite

### Embed Badge

![Health badge](/badges/ip2location-ip2location-csv-converter/health.svg)

```
[![Health](https://phpackages.com/badges/ip2location-ip2location-csv-converter/health.svg)](https://phpackages.com/packages/ip2location-ip2location-csv-converter)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M708](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M637](/packages/league-csv)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M128](/packages/openspout-openspout)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[ip2location/ip2location-php

\[Official Release\] IP2Location PHP API to get location info from IPv4 and IPv6 address.

2133.9M33](/packages/ip2location-ip2location-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
