|
|
|
@ -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)
|
|
|
|
|