Skip to content

Commit

Permalink
Added support for IP2Location BIN format
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed May 8, 2024
1 parent 2b92f16 commit cafe97d
Show file tree
Hide file tree
Showing 8 changed files with 2,065 additions and 59 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ IP2Location DB1 CSV => MMDB (compatible with GeoLite2-Country MMDB format)

IP2Location DB9 CSV => MMDB (compatible with GeoLite2-City MMDB format)

IP2Location IPv6 CSV (DB1 to DB26 supported) => IP2Location BIN (compatible with all official IP2Location SDK & libraries)


Installation
============
Expand All @@ -32,8 +34,8 @@ $GOPATH/bin/ip2convert
#### Debian/Ubuntu (amd64)

```bash
curl -LO https://github.com/ip2location/ip2convert/releases/download/v1.1.0/ip2convert-1.1.0.deb
sudo dpkg -i ip2convert-1.1.0.deb
curl -LO https://github.com/ip2location/ip2convert/releases/download/v1.2.0/ip2convert-1.2.0.deb
sudo dpkg -i ip2convert-1.2.0.deb
```


Expand Down Expand Up @@ -87,12 +89,12 @@ After choosing a platform `PLAT` from above, run:

```bash
# for Windows, use ".zip" instead of ".tar.gz"
curl -LO https://github.com/ip2location/ip2convert/releases/download/v1.1.0/ip2convert_1.1.0_${PLAT}.tar.gz
curl -LO https://github.com/ip2location/ip2convert/releases/download/v1.2.0/ip2convert_1.2.0_${PLAT}.tar.gz
# OR
wget https://github.com/ip2location/ip2convert/releases/download/v1.1.0/ip2convert_1.1.0_${PLAT}.tar.gz
wget https://github.com/ip2location/ip2convert/releases/download/v1.2.0/ip2convert_1.2.0_${PLAT}.tar.gz

tar -xvf ip2convert_1.1.0_${PLAT}.tar.gz
mv ip2convert_1.1.0_${PLAT} /usr/local/bin/ip2convert
tar -xvf ip2convert_1.2.0_${PLAT}.tar.gz
mv ip2convert_1.2.0_${PLAT} /usr/local/bin/ip2convert
```


Expand Down Expand Up @@ -130,6 +132,19 @@ ip2convert csv2mmdb -t city -i \myfolder\IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGI
```


### Convert IP2Location IPv6 CSV into IP2Location BIN format (compatible with official IP2Location SDK & libraries)

For the commercial CSVs, please go to https://www.ip2location.com/database/ip2location

For the free LITE CSVs, please go to https://lite.ip2location.com/ip2location-lite

DB1 to DB26 are supported.

```bash
ip2convert csv2bin -d 26 -i \myfolder\IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.CSV -o \myfolder\DB26IPV6.BIN
```


LICENCE
=====================
See the LICENSE file.
6 changes: 5 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
ip2convert (1.1.0) jammy; urgency=medium
ip2convert (1.2.0) jammy; urgency=medium

* 1.2.0 added support for IP2Location BIN format.

-- IP2Location <[email protected]> Wed, 8 May 2024 13:34:19 +0800

* 1.1.0 added support for MMDB Country format.

Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Vcs-browser: https://github.com/ip2location/ip2convert
Homepage: https://www.ip2location.com
XS-Go-Import-Path: github.com/ip2location/ip2convert
Package: ip2convert
Version: 1.1.0
Version: 1.2.0
Architecture: amd64
Description: This is the official CLI for converting IP2Location CSV to MMDB.
51 changes: 50 additions & 1 deletion ip2convert/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ import (
"fmt"
"math/big"
"os"
"regexp"
"strings"
)

var cmdCSV2MMDBInput string
var cmdCSV2MMDBOutput string
var cmdCSV2MMDBType string
var cmdCSV2BINDBPackage string

const version string = "1.1.0"
var cmdCSV2BINInput string
var cmdCSV2BINOutput string

const version string = "1.2.0"
const programName string = "ip2convert Geolocation File Format Converter"

var showVer bool = false
var maxIPv4Range *big.Int
var maxIPv4RangePlusOne *big.Int
var maxIPv6Range *big.Int

func init() {
maxIPv4Range = big.NewInt(4294967295)
maxIPv4RangePlusOne = big.NewInt(4294967296)
maxIPv6Range = big.NewInt(0)
maxIPv6Range.SetString("340282366920938463463374607431768211455", 10)
}
Expand All @@ -31,6 +38,11 @@ func main() {
cmdCSV2MMDB.StringVar(&cmdCSV2MMDBOutput, "o", "", "Output MMDB file")
cmdCSV2MMDB.StringVar(&cmdCSV2MMDBType, "t", "", "MMDB file type")

cmdCSV2BIN := flag.NewFlagSet("csv2bin", flag.ExitOnError)
cmdCSV2BIN.StringVar(&cmdCSV2BINDBPackage, "d", "", "DB package")
cmdCSV2BIN.StringVar(&cmdCSV2BINInput, "i", "", "Input CSV file")
cmdCSV2BIN.StringVar(&cmdCSV2BINOutput, "o", "", "Output BIN file")

flag.BoolVar(&showVer, "v", false, "Show version")

flag.Usage = func() {
Expand Down Expand Up @@ -66,6 +78,26 @@ func main() {
return
}
ConvertCSV2MMDB(cmdCSV2MMDBInput, cmdCSV2MMDBOutput, cmdCSV2MMDBType)
case "csv2bin":
cmdCSV2BIN.Parse(os.Args[2:])
cmdCSV2BINDBPackage = strings.TrimSpace(cmdCSV2BINDBPackage)
cmdCSV2BINInput = strings.TrimSpace(cmdCSV2BINInput)
cmdCSV2BINOutput = strings.TrimSpace(cmdCSV2BINOutput)
regexDBPackage := regexp.MustCompile(`^(([1-9])|(1[0-9])|(2[0-6]))$`) // 1 to 26 for the DB packages

if !regexDBPackage.MatchString(cmdCSV2BINDBPackage) {
fmt.Println("DB package not specified.")
return
}
if cmdCSV2BINInput == "" {
fmt.Println("Input file not specified.")
return
}
if cmdCSV2BINOutput == "" {
fmt.Println("Output file not specified.")
return
}
WriteBIN(cmdCSV2BINInput, cmdCSV2BINOutput, cmdCSV2BINDBPackage)
default:
flag.Parse()
if showVer {
Expand Down Expand Up @@ -123,6 +155,23 @@ NOTE:
OR download the free LITE DB9 from https://lite.ip2location.com
To convert IP2Location DB CSV to IP2Location BIN
Usage: EXE csv2bin [OPTION]
-d Specify the IP2Location DB package
Valid values: 1 to 26
-i Specify the input path to the DB CSV file
-o Specify the output path to the BIN file
NOTE:
The conversion requires the IP2Location DB CSV file.
You can either subscribe to the commercial DB at https://www.ip2location.com
OR download the free LITE DB from https://lite.ip2location.com
`

usage = strings.ReplaceAll(usage, "EXE", os.Args[0])
Expand Down
Loading

0 comments on commit cafe97d

Please sign in to comment.