ip2location-python-csv-converter


Nameip2location-python-csv-converter JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/ip2location/ip2location-python-csv-converter
SummaryPython script to converts IP2Location CSV database into IP range or CIDR format.
upload_time2023-11-29 02:17:42
maintainer
docs_urlNone
authorIP2Location
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
licenseMIT
keywords ip2location geolocation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # IP2Location Python CSV Converter

This Python 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 DB26 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.

## Requirement

This script require *ipaddress* to work. For Python3 user, it is already been installed as part of Python3 standard library. For Python2 user, if you do not have the library installed, you can install the library by running the following command:

`pip install ipaddress`

For Windows user, please install this library *win_inet_pton* before using this script, you can install the library by running the following command:

`pip install win-inet-pton`

## Installation

You can install the script by using pip command:

`pip install ip2location-python-csv-converter`

## Usage

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

#### Parameters

| Parameter | Description                                                  |
| --------- | ------------------------------------------------------------ |
| -range    | IP numbers will be converted into the first IP address and last IP address in the range. |
| -cidr     | IP numbers will be converted into CIDR format.               |
| -hex      | IP numbers will be converted into hexadecimal format. (auto padding)        |
| -hex4     | IP numbers will be converted into hexadecimal format. (pad IPv4)        |
| -hex6     | IP numbers will be converted into hexadecimal format. (pad IPv6)        |
| -replace  | The IP numbers in will be replaced to the selected format.   |
| -append   | The converted format will be appended after the IP numbers field. |

### Example:

##### 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:

Command:

```
ip2location-csv-converter -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:

Command:

```
ip2location-csv-converter -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:

Command:

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

Output:

```
"01060000","0107ffff","IN","India"
"01080000","0108ffff","CN","China"
"01090000","0109ffff","MY","Malaysia"
"010a0000","010a09ff","CN","China"
"010a0a00","010a0aff","AU","Australia"
"010a0b00","010a7fff","CN","China"
"010a8000","010affff","TH","Thailand"
"010b0000","010bffff","KR","Korea, Republic of"
"010c0000","010fffff","CN","China"
"01100000","01103fff","KR","Korea, Republic of"
```

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

Command:

```
ip2location-csv-converter -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:

Command:

```
ip2location-csv-converter -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"
```

##### Convert into hexadecimal with append option:

Command:

```
ip2location-csv-converter -hex -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV
```

Output:

```
"01060000","0107ffff","17170432","17301503","IN","India"
"01080000","0108ffff","17301504","17367039","CN","China"
"01090000","0109ffff","17367040","17432575","MY","Malaysia"
"010a0000","010a09ff","17432576","17435135","CN","China"
"010a0a00","010a0aff","17435136","17435391","AU","Australia"
"010a0b00","010a7fff","17435392","17465343","CN","China"
"010a8000","010affff","17465344","17498111","TH","Thailand"
"010b0000","010bffff","17498112","17563647","KR","Korea, Republic of"
"010c0000","010fffff","17563648","17825791","CN","China"
"01100000","01103fff","17825792","17842175","KR","Korea, Republic of"
```

## 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

URL: [https://www.ip2location.com](https://www.ip2location.com/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ip2location/ip2location-python-csv-converter",
    "name": "ip2location-python-csv-converter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
    "maintainer_email": "",
    "keywords": "IP2Location Geolocation",
    "author": "IP2Location",
    "author_email": "support@ip2location.com",
    "download_url": "https://files.pythonhosted.org/packages/cb/84/a3ce5922aab0b3c1ee0fbc0818be530693780922968c5b36d9f535158d32/ip2location-python-csv-converter-1.2.3.tar.gz",
    "platform": null,
    "description": "# IP2Location Python CSV Converter\r\n\r\nThis Python 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 DB26 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).\r\n\r\nYou can download the IP2Location CSV file at the below links:\r\n\r\n- [IP2Location Commercial Database](https://www.ip2location.com/)\r\n- [IP2Location LITE Database](https://lite.ip2location.com/)\r\n\r\nPlease do not use this script to convert IP2Location BIN data file. It only support the CSV format, not the binary format.\r\n\r\n## Requirement\r\n\r\nThis script require *ipaddress* to work. For Python3 user, it is already been installed as part of Python3 standard library. For Python2 user, if you do not have the library installed, you can install the library by running the following command:\r\n\r\n`pip install ipaddress`\r\n\r\nFor Windows user, please install this library *win_inet_pton* before using this script, you can install the library by running the following command:\r\n\r\n`pip install win-inet-pton`\r\n\r\n## Installation\r\n\r\nYou can install the script by using pip command:\r\n\r\n`pip install ip2location-python-csv-converter`\r\n\r\n## Usage\r\n\r\n```\r\nip2location-csv-converter [-range | -cidr | -hex] [-replace | -append] INPUT_FILE OUTPUT_FILE\r\n```\r\n\r\n#### Parameters\r\n\r\n| Parameter | Description                                                  |\r\n| --------- | ------------------------------------------------------------ |\r\n| -range    | IP numbers will be converted into the first IP address and last IP address in the range. |\r\n| -cidr     | IP numbers will be converted into CIDR format.               |\r\n| -hex      | IP numbers will be converted into hexadecimal format. (auto padding)        |\r\n| -hex4     | IP numbers will be converted into hexadecimal format. (pad IPv4)        |\r\n| -hex6     | IP numbers will be converted into hexadecimal format. (pad IPv6)        |\r\n| -replace  | The IP numbers in will be replaced to the selected format.   |\r\n| -append   | The converted format will be appended after the IP numbers field. |\r\n\r\n### Example:\r\n\r\n##### Sample Input\r\n\r\n```\r\n\"17170432\",\"17301503\",\"IN\",\"India\"\r\n\"17301504\",\"17367039\",\"CN\",\"China\"\r\n\"17367040\",\"17432575\",\"MY\",\"Malaysia\"\r\n\"17432576\",\"17435135\",\"CN\",\"China\"\r\n\"17435136\",\"17435391\",\"AU\",\"Australia\"\r\n\"17435392\",\"17465343\",\"CN\",\"China\"\r\n\"17465344\",\"17498111\",\"TH\",\"Thailand\"\r\n\"17498112\",\"17563647\",\"KR\",\"Korea, Republic of\"\r\n\"17563648\",\"17825791\",\"CN\",\"China\"\r\n\"17825792\",\"17842175\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n##### Convert into range with replace option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -range -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"1.6.0.0\",\"1.7.255.255\",\"IN\",\"India\"\r\n\"1.8.0.0\",\"1.8.255.255\",\"CN\",\"China\"\r\n\"1.9.0.0\",\"1.9.255.255\",\"MY\",\"Malaysia\"\r\n\"1.10.0.0\",\"1.10.9.255\",\"CN\",\"China\"\r\n\"1.10.10.0\",\"1.10.10.255\",\"AU\",\"Australia\"\r\n\"1.10.11.0\",\"1.10.127.255\",\"CN\",\"China\"\r\n\"1.10.128.0\",\"1.10.255.255\",\"TH\",\"Thailand\"\r\n\"1.11.0.0\",\"1.11.255.255\",\"KR\",\"Korea, Republic of\"\r\n\"1.12.0.0\",\"1.15.255.255\",\"CN\",\"China\"\r\n\"1.16.0.0\",\"1.16.63.255\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n##### Convert into CIDR with replace option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -cidr -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"1.6.0.0/15\",\"IN\",\"India\"\r\n\"1.8.0.0/16\",\"CN\",\"China\"\r\n\"1.9.0.0/16\",\"MY\",\"Malaysia\"\r\n\"1.10.0.0/21\",\"CN\",\"China\"\r\n\"1.10.8.0/23\",\"CN\",\"China\"\r\n\"1.10.10.0/24\",\"AU\",\"Australia\"\r\n\"1.10.11.0/24\",\"CN\",\"China\"\r\n\"1.10.12.0/22\",\"CN\",\"China\"\r\n\"1.10.16.0/20\",\"CN\",\"China\"\r\n\"1.10.32.0/19\",\"CN\",\"China\"\r\n```\r\n\r\n##### Convert into hexadecimal with replace option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -hex -replace IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"01060000\",\"0107ffff\",\"IN\",\"India\"\r\n\"01080000\",\"0108ffff\",\"CN\",\"China\"\r\n\"01090000\",\"0109ffff\",\"MY\",\"Malaysia\"\r\n\"010a0000\",\"010a09ff\",\"CN\",\"China\"\r\n\"010a0a00\",\"010a0aff\",\"AU\",\"Australia\"\r\n\"010a0b00\",\"010a7fff\",\"CN\",\"China\"\r\n\"010a8000\",\"010affff\",\"TH\",\"Thailand\"\r\n\"010b0000\",\"010bffff\",\"KR\",\"Korea, Republic of\"\r\n\"010c0000\",\"010fffff\",\"CN\",\"China\"\r\n\"01100000\",\"01103fff\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n##### Convert into range with append option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -range -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"17170432\",\"17301503\",\"1.6.0.0\",\"1.7.255.255\",\"IN\",\"India\"\r\n\"17301504\",\"17367039\",\"1.8.0.0\",\"1.8.255.255\",\"CN\",\"China\"\r\n\"17367040\",\"17432575\",\"1.9.0.0\",\"1.9.255.255\",\"MY\",\"Malaysia\"\r\n\"17432576\",\"17435135\",\"1.10.0.0\",\"1.10.9.255\",\"CN\",\"China\"\r\n\"17435136\",\"17435391\",\"1.10.10.0\",\"1.10.10.255\",\"AU\",\"Australia\"\r\n\"17435392\",\"17465343\",\"1.10.11.0\",\"1.10.127.255\",\"CN\",\"China\"\r\n\"17465344\",\"17498111\",\"1.10.128.0\",\"1.10.255.255\",\"TH\",\"Thailand\"\r\n\"17498112\",\"17563647\",\"1.11.0.0\",\"1.11.255.255\",\"KR\",\"Korea, Republic of\"\r\n\"17563648\",\"17825791\",\"1.12.0.0\",\"1.15.255.255\",\"CN\",\"China\"\r\n\"17825792\",\"17842175\",\"1.16.0.0\",\"1.16.63.255\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n##### Convert into CIDR with append option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -cidr -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"17170432\",\"17301503\",\"1.6.0.0/15\",\"IN\",\"India\"\r\n\"17301504\",\"17367039\",\"1.8.0.0/16\",\"CN\",\"China\"\r\n\"17367040\",\"17432575\",\"1.9.0.0/16\",\"MY\",\"Malaysia\"\r\n\"17432576\",\"17435135\",\"1.10.0.0/21\",\"CN\",\"China\"\r\n\"17432576\",\"17435135\",\"1.10.8.0/23\",\"CN\",\"China\"\r\n\"17435136\",\"17435391\",\"1.10.10.0/24\",\"AU\",\"Australia\"\r\n\"17435392\",\"17465343\",\"1.10.11.0/24\",\"CN\",\"China\"\r\n\"17435392\",\"17465343\",\"1.10.12.0/22\",\"CN\",\"China\"\r\n\"17435392\",\"17465343\",\"1.10.16.0/20\",\"CN\",\"China\"\r\n\"17435392\",\"17465343\",\"1.10.32.0/19\",\"CN\",\"China\"\r\n\"17435392\",\"17465343\",\"1.10.64.0/18\",\"CN\",\"China\"\r\n\"17465344\",\"17498111\",\"1.10.128.0/17\",\"TH\",\"Thailand\"\r\n\"17498112\",\"17563647\",\"1.11.0.0/16\",\"KR\",\"Korea, Republic of\"\r\n\"17563648\",\"17825791\",\"1.12.0.0/14\",\"CN\",\"China\"\r\n\"17825792\",\"17842175\",\"1.16.0.0/18\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n##### Convert into hexadecimal with append option:\r\n\r\nCommand:\r\n\r\n```\r\nip2location-csv-converter -hex -append IP2LOCATION-DB1.CSV IP2LOCATION-DB1.NEW.CSV\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n\"01060000\",\"0107ffff\",\"17170432\",\"17301503\",\"IN\",\"India\"\r\n\"01080000\",\"0108ffff\",\"17301504\",\"17367039\",\"CN\",\"China\"\r\n\"01090000\",\"0109ffff\",\"17367040\",\"17432575\",\"MY\",\"Malaysia\"\r\n\"010a0000\",\"010a09ff\",\"17432576\",\"17435135\",\"CN\",\"China\"\r\n\"010a0a00\",\"010a0aff\",\"17435136\",\"17435391\",\"AU\",\"Australia\"\r\n\"010a0b00\",\"010a7fff\",\"17435392\",\"17465343\",\"CN\",\"China\"\r\n\"010a8000\",\"010affff\",\"17465344\",\"17498111\",\"TH\",\"Thailand\"\r\n\"010b0000\",\"010bffff\",\"17498112\",\"17563647\",\"KR\",\"Korea, Republic of\"\r\n\"010c0000\",\"010fffff\",\"17563648\",\"17825791\",\"CN\",\"China\"\r\n\"01100000\",\"01103fff\",\"17825792\",\"17842175\",\"KR\",\"Korea, Republic of\"\r\n```\r\n\r\n## Custom Input File\r\n\r\nYou 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.\r\n\r\n## Support\r\n\r\nURL: [https://www.ip2location.com](https://www.ip2location.com/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python script to converts IP2Location CSV database into IP range or CIDR format.",
    "version": "1.2.3",
    "project_urls": {
        "Homepage": "https://github.com/ip2location/ip2location-python-csv-converter",
        "Official Website": "https://www.ip2location.com"
    },
    "split_keywords": [
        "ip2location",
        "geolocation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c16eefd7ac7d948bafb57ccd1e94fd68b3fb81f617e1f861de032266c84052d",
                "md5": "c6af51c1bba86d7d9533e8fc16f7781c",
                "sha256": "d41a672f0846cb202bd89300fd504dc951228f738441d5a4c14dd1ae690f6a4c"
            },
            "downloads": -1,
            "filename": "ip2location_python_csv_converter-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6af51c1bba86d7d9533e8fc16f7781c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
            "size": 7288,
            "upload_time": "2023-11-29T02:17:41",
            "upload_time_iso_8601": "2023-11-29T02:17:41.191021Z",
            "url": "https://files.pythonhosted.org/packages/2c/16/eefd7ac7d948bafb57ccd1e94fd68b3fb81f617e1f861de032266c84052d/ip2location_python_csv_converter-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb84a3ce5922aab0b3c1ee0fbc0818be530693780922968c5b36d9f535158d32",
                "md5": "af8ea99b6839efdfaa158728daf23206",
                "sha256": "77c8b426e48832f411633ab90255a1ca77d7e2abbedf0bf05d96fd4f92c63e0f"
            },
            "downloads": -1,
            "filename": "ip2location-python-csv-converter-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "af8ea99b6839efdfaa158728daf23206",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
            "size": 6717,
            "upload_time": "2023-11-29T02:17:42",
            "upload_time_iso_8601": "2023-11-29T02:17:42.420289Z",
            "url": "https://files.pythonhosted.org/packages/cb/84/a3ce5922aab0b3c1ee0fbc0818be530693780922968c5b36d9f535158d32/ip2location-python-csv-converter-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-29 02:17:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ip2location",
    "github_project": "ip2location-python-csv-converter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ip2location-python-csv-converter"
}
        
Elapsed time: 0.15566s