mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2026-01-03 09:49:04 +08:00
better handle hijack dns and underlying conflicts
This commit is contained in:
parent
1356333018
commit
e9efee0746
@ -22,7 +22,7 @@ var customDNS []netip.Addr
|
||||
var dnsIsSet bool
|
||||
|
||||
func HandleInterfaceChange(_ *control.Interface, _ int) {
|
||||
monitorForUnderlyingDNS()
|
||||
monitorForUnderlyingDNS(customDNS)
|
||||
if !dnsIsSet {
|
||||
return
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package boxdns
|
||||
import (
|
||||
"github.com/matsuridayo/libneko/iphlpapi"
|
||||
"log"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
tun "github.com/sagernet/sing-tun"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
|
||||
var DefaultIfcMonitor tun.DefaultInterfaceMonitor
|
||||
|
||||
func monitorForUnderlyingDNS() {
|
||||
func monitorForUnderlyingDNS(customDNS []netip.Addr) {
|
||||
ifc := DefaultIfcMonitor.DefaultInterface()
|
||||
if ifc == nil {
|
||||
log.Println("Default interface is nil!")
|
||||
@ -32,8 +33,13 @@ func monitorForUnderlyingDNS() {
|
||||
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7],
|
||||
})
|
||||
guidStr := "{" + u.String() + "}"
|
||||
if getFirstDNS(guidStr) != underlyingDNS {
|
||||
underlyingDNS = getFirstDNS(guidStr)
|
||||
dns := getFirstDNS(guidStr)
|
||||
if len(customDNS) > 0 && dns == customDNS[0].String() {
|
||||
log.Println("Interface DNS is the same as Hijack dns, You may need to fix it manually!")
|
||||
return
|
||||
}
|
||||
if dns != "" && dns != underlyingDNS {
|
||||
underlyingDNS = dns
|
||||
log.Println("underlyingDNS:", guidStr, underlyingDNS)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user