mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-12 19:30:25 +08:00
IP库阶段性提交(未完成)
This commit is contained in:
2
pkg/iplibrary/.gitignore
vendored
2
pkg/iplibrary/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
ip.db
|
ip.db
|
||||||
Binary file not shown.
@@ -169,14 +169,15 @@ func (this *Reader) parse(data []byte) (left []byte, err error) {
|
|||||||
return nil, errors.New("invalid ip version '" + string(line) + "'")
|
return nil, errors.New("invalid ip version '" + string(line) + "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ipFrom uint64
|
||||||
|
var ipTo uint64
|
||||||
if len(pieces[2]) == 0 {
|
if len(pieces[2]) == 0 {
|
||||||
pieces[2] = pieces[1]
|
pieces[2] = pieces[1]
|
||||||
}
|
ipFrom = types.Uint64(pieces[1])
|
||||||
|
ipTo = types.Uint64(pieces[2])
|
||||||
var ipFrom = types.Uint64(pieces[1])
|
} else {
|
||||||
var ipTo = types.Uint64(pieces[2])
|
ipFrom = types.Uint64(pieces[1])
|
||||||
if ipFrom > ipTo {
|
ipTo = types.Uint64(pieces[2]) + ipFrom
|
||||||
ipFrom, ipTo = ipTo, ipFrom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if version == "4" {
|
if version == "4" {
|
||||||
|
|||||||
@@ -96,13 +96,20 @@ func (this *Writer) Write(ipFrom string, ipTo string, countryId int64, provinceI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
pieces = append(pieces, types.String(configutils.IP2Long(fromIP)))
|
var fromIPLong = configutils.IP2Long(fromIP)
|
||||||
|
var toIPLong = configutils.IP2Long(toIP)
|
||||||
|
|
||||||
|
if toIPLong < fromIPLong {
|
||||||
|
fromIPLong, toIPLong = toIPLong, fromIPLong
|
||||||
|
}
|
||||||
|
|
||||||
|
pieces = append(pieces, types.String(fromIPLong))
|
||||||
if ipFrom == ipTo {
|
if ipFrom == ipTo {
|
||||||
// 2
|
// 2
|
||||||
pieces = append(pieces, "")
|
pieces = append(pieces, "")
|
||||||
} else {
|
} else {
|
||||||
// 2
|
// 2
|
||||||
pieces = append(pieces, types.String(configutils.IP2Long(toIP)))
|
pieces = append(pieces, types.String(toIPLong-fromIPLong))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3
|
// 3
|
||||||
|
|||||||
Reference in New Issue
Block a user