mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 05:31:18 +08:00
4ab986cccb
dns-hijack: - 1.1.1.1 - 8.8.8.8:53 - tcp://1.1.1.1:53 - udp://223.5.5.5 - 10.0.0.1:5353
47 lines
827 B
Go
47 lines
827 B
Go
package net
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func SplitNetworkType(s string) (string, string, error) {
|
|
var (
|
|
shecme string
|
|
hostPort string
|
|
)
|
|
result := strings.Split(s, "://")
|
|
if len(result) == 2 {
|
|
shecme = result[0]
|
|
hostPort = result[1]
|
|
} else if len(result) == 1 {
|
|
hostPort = result[0]
|
|
} else {
|
|
return "", "", fmt.Errorf("tcp/udp style error")
|
|
}
|
|
|
|
if len(shecme) == 0 {
|
|
shecme = "udp"
|
|
}
|
|
|
|
if shecme != "tcp" && shecme != "udp" {
|
|
return "", "", fmt.Errorf("scheme should be tcp:// or udp://")
|
|
} else {
|
|
return shecme, hostPort, nil
|
|
}
|
|
}
|
|
|
|
func SplitHostPort(s string) (host, port string, hasPort bool, err error) {
|
|
temp := s
|
|
hasPort = true
|
|
|
|
if !strings.Contains(s, ":") && !strings.Contains(s, "]:") {
|
|
temp += ":0"
|
|
hasPort = false
|
|
}
|
|
|
|
host, port, err = net.SplitHostPort(temp)
|
|
return
|
|
}
|