master v1.0.28
李光春 2 years ago
parent ba6cce92eb
commit 73395b29a9

@ -1,3 +1,3 @@
package goip
const Version = "1.0.27"
const Version = "1.0.28"

@ -6,6 +6,7 @@ import (
"go.dtapp.net/gostring"
"io/ioutil"
"log"
"net"
"os"
"strconv"
"strings"
@ -36,7 +37,7 @@ type Ip2Region struct {
dbFile string
}
//go:embed ip2region.db
//go:embed ip.db
var dbBinStr []byte
type IpInfo struct {
@ -89,6 +90,11 @@ func getIpInfo(ipStr string, cityId int64, line []byte) (ipInfo IpInfo) {
func (r *Ip2Region) MemorySearch(ipStr string) (ipInfo IpInfo, err error) {
ipInfo.IP = ipStr
if net.ParseIP(ipStr).To4() == nil {
if net.ParseIP(ipStr).To16() == nil {
return ipInfo, err
}
}
if r.totalBlocks == 0 {

@ -20,7 +20,7 @@ var (
end uint32
)
//go:embed qqwry.dat
//go:embed ip.dat
var dat []byte
type Pointer struct {
@ -62,11 +62,11 @@ func (q *Pointer) readData(length uint32) (rs []byte) {
}
// Find ip地址查询对应归属地信息
func (q *Pointer) Find(ip string) (res Result) {
func (q *Pointer) Find(ipStr string) (res Result) {
// 赋值
res.IP = ip
if net.ParseIP("61.241.55.180").To4() == nil {
res.IP = ipStr
if net.ParseIP(ipStr).To4() == nil {
// 不是ip地址
return res
}
@ -74,7 +74,7 @@ func (q *Pointer) Find(ip string) (res Result) {
q.Offset = 0
// 偏移
offset = q.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
offset = q.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ipStr).To4()))
if offset <= 0 {
return
}

@ -31,7 +31,7 @@ type Result struct {
Isp string `json:"isp,omitempty"` // 运营商
}
//go:embed ipv6wry.db
//go:embed ip.db
var dat []byte
type Pointer struct {
@ -66,15 +66,19 @@ func (q *Pointer) readData(length uint32) (rs []byte) {
}
// Find ip地址查询对应归属地信息
func (q *Pointer) Find(ip string) (res Result) {
func (q *Pointer) Find(ipStr string) (res Result) {
res = Result{}
res.IP = ip
res.IP = ipStr
if net.ParseIP(ipStr).To16() == nil {
return Result{}
}
q.Offset = 0
tp := big.NewInt(0)
op := big.NewInt(0)
tp.SetBytes(net.ParseIP(ip).To16())
tp.SetBytes(net.ParseIP(ipStr).To16())
op.SetString("18446744073709551616", 10)
op.Div(tp, op)
tp.SetString("FFFFFFFFFFFFFFFF", 16)

Loading…
Cancel
Save