diff --git a/README.md b/README.md index 86afa2c..5d354a2 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ nexttrace --no-color 1.1.1.1 export NO_COLOR=1 ``` -#### `NextTrace` supports users to select their own IP API (currently supports: `LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`, `Ip2region`, `IPInfoLocal`, `CHUNZHEN`) +#### `NextTrace` supports users to select their own IP API (currently supports: `LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`, `IPInfoLocal`, `CHUNZHEN`) ```bash # You can specify the IP database by yourself [IP-API.com here], if not specified, LeoMoeAPI will be used @@ -306,7 +306,6 @@ nexttrace --data-provider ip-api.com ## Current directory, nexttrace binary directory and FHS directories (Unix-like) will be searched. ## To customize it, please use environment variables, export NEXTTRACE_IPINFOLOCALPATH=/xxx/yyy.mmdb -## For the offline database Ip2region, you can download it manually and rename it to ip2region.db, or let NextTrace download it automatically ## Please be aware: Due to the serious abuse of IP.SB, you will often be not able to query IP data from this source ## IP-API.com has a stricter restiction on API calls, if you can't query IP data from this source, please try again in a few minutes @@ -353,7 +352,7 @@ Usage: nexttrace [-h|--help] [--init] [-4|--ipv4] [-6|--ipv6] [-T|--tcp] [--icmp-mode ] [-q|--queries ] [--parallel-requests ] [-m|--max-hops ] [--max-attempts ] [-d|--data-provider - (Ip2region|ip2region|IP.SB|ip.sb|IPInfo|ipinfo|IPInsight|ipinsight|IPAPI.com|ip-api.com|IPInfoLocal|ipinfolocal|chunzhen|LeoMoeAPI|leomoeapi|ipdb.one|disable-geoip)] + (IP.SB|ip.sb|IPInfo|ipinfo|IPInsight|ipinsight|IPAPI.com|ip-api.com|IPInfoLocal|ipinfolocal|chunzhen|LeoMoeAPI|leomoeapi|ipdb.one|disable-geoip)] [--pow-provider (api.nxtrace.org|sakura)] [-n|--no-rdns] [-a|--always-rdns] [-P|--route-path] [-r|--report] [--dn42] [-o|--output] [-t|--table] [--raw] [-j|--json] [-c|--classic] @@ -392,8 +391,8 @@ Arguments: --max-attempts Set the max number of attempts per TTL (instead of a fixed auto value) -d --data-provider Choose IP Geograph Data Provider [IP.SB, - IPInfo, IPInsight, IP-API.com, Ip2region, - IPInfoLocal, CHUNZHEN, disable-geoip]. + IPInfo, IPInsight, IP-API.com, IPInfoLocal, + CHUNZHEN, disable-geoip]. Default: LeoMoeAPI --pow-provider Choose PoW Provider [api.nxtrace.org, sakura] For China mainland users, please diff --git a/README_zh_CN.md b/README_zh_CN.md index 27ece84..f14887f 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -292,7 +292,7 @@ nexttrace --no-color 1.1.1.1 export NO_COLOR=1 ``` -#### `NextTrace`支持用户自主选择 IP 数据库(目前支持:`LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`, `Ip2region`, `IPInfoLocal`, `CHUNZHEN`) +#### `NextTrace`支持用户自主选择 IP 数据库(目前支持:`LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`, `IPInfoLocal`, `CHUNZHEN`) ```bash # 可以自行指定IP数据库[此处为IP-API.com],不指定则默认为LeoMoeAPI @@ -305,7 +305,6 @@ nexttrace --data-provider ip-api.com ## 默认搜索用户当前路径、程序所在路径、和 FHS 路径(Unix-like) ## 如果需要自定义路径,请设置环境变量 export NEXTTRACE_IPINFOLOCALPATH=/xxx/yyy.mmdb -## 对于离线库 Ip2region 可NextTrace自动下载,也可自行下载并命名为 ip2region.db ## 另外:由于IP.SB被滥用比较严重,会经常出现无法查询的问题,请知悉。 ## IP-API.com限制调用较为严格,如有查询不到的情况,请几分钟后再试。 # 纯真IP数据库默认使用 http://127.0.0.1:2060 作为查询接口,如需自定义请使用环境变量 @@ -336,7 +335,7 @@ Usage: nexttrace [-h|--help] [--init] [-4|--ipv4] [-6|--ipv6] [-T|--tcp] [--icmp-mode ] [-q|--queries ] [--parallel-requests ] [-m|--max-hops ] [--max-attempts ] [-d|--data-provider - (Ip2region|ip2region|IP.SB|ip.sb|IPInfo|ipinfo|IPInsight|ipinsight|IPAPI.com|ip-api.com|IPInfoLocal|ipinfolocal|chunzhen|LeoMoeAPI|leomoeapi|ipdb.one|disable-geoip)] + (IP.SB|ip.sb|IPInfo|ipinfo|IPInsight|ipinsight|IPAPI.com|ip-api.com|IPInfoLocal|ipinfolocal|chunzhen|LeoMoeAPI|leomoeapi|ipdb.one|disable-geoip)] [--pow-provider (api.nxtrace.org|sakura)] [-n|--no-rdns] [-a|--always-rdns] [-P|--route-path] [-r|--report] [--dn42] [-o|--output] [-t|--table] [--raw] [-j|--json] [-c|--classic] @@ -375,8 +374,8 @@ Arguments: --max-attempts Set the max number of attempts per TTL (instead of a fixed auto value) -d --data-provider Choose IP Geograph Data Provider [IP.SB, - IPInfo, IPInsight, IP-API.com, Ip2region, - IPInfoLocal, CHUNZHEN, disable-geoip]. + IPInfo, IPInsight, IP-API.com, IPInfoLocal, + CHUNZHEN, disable-geoip]. Default: LeoMoeAPI --pow-provider Choose PoW Provider [api.nxtrace.org, sakura] For China mainland users, please diff --git a/cmd/cmd.go b/cmd/cmd.go index bc3cc7c..79ca637 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -114,8 +114,8 @@ func Execute() { parallelRequests := parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: "Set ParallelRequests number. It should be 1 when there is a multi-routing"}) maxHops := parser.Int("m", "max-hops", &argparse.Options{Default: 30, Help: "Set the max number of hops (max TTL to be reached)"}) maxAttempts := parser.Int("", "max-attempts", &argparse.Options{Help: "Set the max number of attempts per TTL (instead of a fixed auto value)"}) - dataOrigin := parser.Selector("d", "data-provider", []string{"Ip2region", "ip2region", "IP.SB", "ip.sb", "IPInfo", "ipinfo", "IPInsight", "ipinsight", "IPAPI.com", "ip-api.com", "IPInfoLocal", "ipinfolocal", "chunzhen", "LeoMoeAPI", "leomoeapi", "ipdb.one", "disable-geoip"}, &argparse.Options{Default: "LeoMoeAPI", - Help: "Choose IP Geograph Data Provider [IP.SB, IPInfo, IPInsight, IP-API.com, Ip2region, IPInfoLocal, CHUNZHEN, disable-geoip]"}) + dataOrigin := parser.Selector("d", "data-provider", []string{"IP.SB", "ip.sb", "IPInfo", "ipinfo", "IPInsight", "ipinsight", "IPAPI.com", "ip-api.com", "IPInfoLocal", "ipinfolocal", "chunzhen", "LeoMoeAPI", "leomoeapi", "ipdb.one", "disable-geoip"}, &argparse.Options{Default: "LeoMoeAPI", + Help: "Choose IP Geograph Data Provider [IP.SB, IPInfo, IPInsight, IP-API.com, IPInfoLocal, CHUNZHEN, disable-geoip]"}) powProvider := parser.Selector("", "pow-provider", []string{"api.nxtrace.org", "sakura"}, &argparse.Options{Default: "api.nxtrace.org", Help: "Choose PoW Provider [api.nxtrace.org, sakura] For China mainland users, please use sakura"}) norDNS := parser.Flag("n", "no-rdns", &argparse.Options{Help: "Do not resolve IP addresses to their domain names"}) diff --git a/go.mod b/go.mod index ecfe388..2899bb3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/gin-gonic/gin v1.11.0 github.com/google/gopacket v1.1.19 github.com/gorilla/websocket v1.5.3 - github.com/lionsoul2014/ip2region v3.7.0+incompatible github.com/oschwald/maxminddb-golang v1.13.1 github.com/rodaine/table v1.3.0 github.com/spf13/viper v1.21.0 @@ -22,8 +21,6 @@ require ( golang.org/x/sys v0.37.0 ) -replace github.com/lionsoul2014/ip2region => github.com/lionsoul2014/ip2region v2.11.2+incompatible - require ( github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.14.1 // indirect diff --git a/go.sum b/go.sum index 4367862..1520f2b 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= -github.com/lionsoul2014/ip2region v2.11.2+incompatible h1:+VRsGcrHz8ewXI/2UzTptJlACsxD/p4xCxuql4u2nKU= -github.com/lionsoul2014/ip2region v2.11.2+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= diff --git a/ipgeo/ip2region.go b/ipgeo/ip2region.go deleted file mode 100644 index 4ca600f..0000000 --- a/ipgeo/ip2region.go +++ /dev/null @@ -1,88 +0,0 @@ -package ipgeo - -import ( - "errors" - "fmt" - "io" - "net/http" - "os" - "time" - - "github.com/lionsoul2014/ip2region/v1.0/binding/golang/ip2region" -) - -const ( - ipDataBasePath = "./ip2region.db" - defaultDownURL = "1" - originURL = "https://mirror.ghproxy.com/?q=https://github.com/bqf9979/ip2region/blob/master/data/ip2region.db?raw=true" -) - -func downloadDataBase() error { - fmt.Println("Downloading DataBase...") - resp, err := http.Get(originURL) - if err != nil { - return err - } - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - panic(err) - } - }(resp.Body) - - // Create the file - out, err := os.Create(ipDataBasePath) - if err != nil { - return err - } - defer func(out *os.File) { - err := out.Close() - if err != nil { - panic(err) - } - }(out) - - // Write the body to file - _, err = io.Copy(out, resp.Body) - return err -} - -func IP2Region(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, error) { - if _, err := os.Stat(ipDataBasePath); os.IsNotExist(err) { - if err = downloadDataBase(); err != nil { - panic("Download Failed!") - } - } - region, err := ip2region.New(ipDataBasePath) - if err != nil { - panic("Cannot find ip2region.db") - } - defer region.Close() - info, searchErr := region.MemorySearch(ip) - if searchErr != nil { - return &IPGeoData{}, errors.New("no results") - } - - if info.Country == "0" { - info.Country = "" - } - - if info.Province == "0" { - info.Province = "" - } - - if info.City == "0" { - info.City = "" - } - - if info.ISP == "0" { - info.ISP = "" - } - - return &IPGeoData{ - Owner: info.ISP, - Country: info.Country, - Prov: info.Province, - City: info.City, - }, nil -} diff --git a/ipgeo/ipgeo.go b/ipgeo/ipgeo.go index 11943ee..f1f17da 100644 --- a/ipgeo/ipgeo.go +++ b/ipgeo/ipgeo.go @@ -44,8 +44,6 @@ func GetSource(s string) Source { return IPApiCom case "IPINFO": return IPInfo - case "IP2REGION": - return IP2Region case "IPINFOLOCAL": return IPInfoLocal case "CHUNZHEN":