mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
feat: add IP-ASN rule
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package constant
|
||||
|
||||
var (
|
||||
ASNEnable bool
|
||||
GeodataMode bool
|
||||
GeoAutoUpdate bool
|
||||
GeoUpdateInterval int
|
||||
GeoIpUrl string
|
||||
MmdbUrl string
|
||||
GeoSiteUrl string
|
||||
ASNUrl string
|
||||
)
|
||||
|
||||
@@ -133,7 +133,8 @@ type Metadata struct {
|
||||
Type Type `json:"type"`
|
||||
SrcIP netip.Addr `json:"sourceIP"`
|
||||
DstIP netip.Addr `json:"destinationIP"`
|
||||
DstGeoIP []string `json:"destinationGeoIP"` // can be nil if never queried, empty slice if got no result
|
||||
DstGeoIP []string `json:"destinationGeoIP"` // can be nil if never queried, empty slice if got no result
|
||||
DstIPASN string `json:"destinationIPASN"`
|
||||
SrcPort uint16 `json:"sourcePort,string"` // `,string` is used to compatible with old version json output
|
||||
DstPort uint16 `json:"destinationPort,string"` // `,string` is used to compatible with old version json output
|
||||
InIP netip.Addr `json:"inboundIP"`
|
||||
|
||||
@@ -15,6 +15,7 @@ const Name = "mihomo"
|
||||
var (
|
||||
GeositeName = "GeoSite.dat"
|
||||
GeoipName = "GeoIP.dat"
|
||||
ASNName = "ASN.mmdb"
|
||||
)
|
||||
|
||||
// Path is used to get the configuration path
|
||||
@@ -112,6 +113,25 @@ func (p *path) MMDB() string {
|
||||
return P.Join(p.homeDir, "geoip.metadb")
|
||||
}
|
||||
|
||||
func (p *path) ASN() string {
|
||||
files, err := os.ReadDir(p.homeDir)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, fi := range files {
|
||||
if fi.IsDir() {
|
||||
// 目录则直接跳过
|
||||
continue
|
||||
} else {
|
||||
if strings.EqualFold(fi.Name(), "ASN.mmdb") {
|
||||
ASNName = fi.Name()
|
||||
return P.Join(p.homeDir, fi.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
return P.Join(p.homeDir, ASNName)
|
||||
}
|
||||
|
||||
func (p *path) OldCache() string {
|
||||
return P.Join(p.homeDir, ".cache")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ const (
|
||||
GEOSITE
|
||||
GEOIP
|
||||
IPCIDR
|
||||
IPASN
|
||||
SrcIPCIDR
|
||||
IPSuffix
|
||||
SrcIPSuffix
|
||||
@@ -49,6 +50,8 @@ func (rt RuleType) String() string {
|
||||
return "GeoIP"
|
||||
case IPCIDR:
|
||||
return "IPCIDR"
|
||||
case IPASN:
|
||||
return "IPASN"
|
||||
case SrcIPCIDR:
|
||||
return "SrcIPCIDR"
|
||||
case IPSuffix:
|
||||
|
||||
Reference in New Issue
Block a user