chore: rewrite verifyIP6
This commit is contained in:
parent
47df97322d
commit
4ef99294e7
1 changed files with 6 additions and 14 deletions
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/Dreamacro/clash/adapter/outboundgroup"
|
||||
|
@ -149,20 +150,11 @@ func proxyGroupsDagSort(groupsConfig []map[string]any) error {
|
|||
}
|
||||
|
||||
func verifyIP6() bool {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
ipNet, isIpNet := addr.(*net.IPNet)
|
||||
if isIpNet && !ipNet.IP.IsLoopback() {
|
||||
if ipNet.IP.To16() != nil {
|
||||
s := ipNet.IP.String()
|
||||
for i := 0; i < len(s); i++ {
|
||||
switch s[i] {
|
||||
case ':':
|
||||
return true
|
||||
}
|
||||
if iAddrs, err := net.InterfaceAddrs(); err == nil {
|
||||
for _, addr := range iAddrs {
|
||||
if prefix, err := netip.ParsePrefix(addr.String()); err == nil {
|
||||
if addr := prefix.Addr().Unmap(); addr.Is6() && addr.IsGlobalUnicast() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue