mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
chore: rewrite verifyIP6
This commit is contained in:
parent
47df97322d
commit
4ef99294e7
@ -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 New Issue
Block a user