mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
feat: Handle NAT64 address query (#200)
We can query the NAT64 address by the IPv4 address part of the NAT64 address. This is useful when we want to know the NAT64 address of a specific IPv4 address. We also add a new regex pattern to match the NAT64 address like 64:ff9b::1.1.1.1 . Signed-off-by: Yangyu Chen <cyy@cyyself.name>
This commit is contained in:
parent
2e758d3117
commit
8c17abbd66
@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@ -72,6 +73,19 @@ func Find(typ dbif.QueryType, query string) *Result {
|
||||
if result, found := queryCache.Load(query); found {
|
||||
return result.(*Result)
|
||||
}
|
||||
// Convert NAT64 64:ff9b::/96 to IPv4
|
||||
if typ == dbif.TypeIPv6 {
|
||||
ip := net.ParseIP(query)
|
||||
if ip != nil {
|
||||
_, NAT64, _ := net.ParseCIDR("64:ff9b::/96")
|
||||
if NAT64.Contains(ip) {
|
||||
ip4 := make(net.IP, 4)
|
||||
copy(ip4, ip[12:16])
|
||||
query = ip4.String()
|
||||
typ = dbif.TypeIPv4
|
||||
}
|
||||
}
|
||||
}
|
||||
db := GetDB(typ)
|
||||
result, err := db.Find(query)
|
||||
if err != nil {
|
||||
|
@ -9,7 +9,7 @@ var (
|
||||
DomainRe = regexp.MustCompile(`([a-zA-Z0-9][-a-zA-Z0-9]{0,62}\.)+([a-zA-Z][-a-zA-Z]{0,62})`)
|
||||
|
||||
IPv4Re = regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`)
|
||||
IPv6Re = regexp.MustCompile(`fe80:(:[0-9a-fA-F]{1,4}){0,4}(%\w+)?|([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::[fF]{4}:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?::(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?`)
|
||||
IPv6Re = regexp.MustCompile(`fe80:(:[0-9a-fA-F]{1,4}){0,4}(%\w+)?|([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|64:ff9b::(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|::[fF]{4}:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?::(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?`)
|
||||
)
|
||||
|
||||
func MaybeRegexp(s string) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user