跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

dns_darwin.go

82 行 · 2.6 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package osutil
5
6import (
7 "fmt"
8 "net"
9 "strings"
10
11 "github.com/lima-vm/lima/v2/pkg/sysprof"
12)
13
14func DNSAddresses() ([]string, error) {
15 nwData, err := sysprof.NetworkData()
16 if err != nil {
17 return nil, err
18 }
19 var addresses []string
20 // Return DNS addresses from the first interface that has an IPv4 address.
21 // The networks are in service order already.
22 for _, nw := range nwData {
23 if len(nw.IPv4.Addresses) > 0 {
24 addresses = nw.DNS.ServerAddresses
25 break
26 }
27 }
28 return addresses, nil
29}
30
31func proxyURL(proxy string, port any) string {
32 if strings.Contains(proxy, "://") {
33 if portNumber, ok := port.(float64); ok && portNumber != 0 {
34 proxy = fmt.Sprintf("%s:%.0f", proxy, portNumber)
35 } else if portString, ok := port.(string); ok && portString != "" {
36 proxy = fmt.Sprintf("%s:%s", proxy, portString)
37 }
38 } else {
39 if portNumber, ok := port.(float64); ok && portNumber != 0 {
40 proxy = net.JoinHostPort(proxy, fmt.Sprintf("%.0f", portNumber))
41 } else if portString, ok := port.(string); ok && portString != "" {
42 proxy = net.JoinHostPort(proxy, portString)
43 }
44 proxy = "http://" + proxy
45 }
46 return proxy
47}
48
49func ProxySettings() (map[string]string, error) {
50 nwData, err := sysprof.NetworkData()
51 if err != nil {
52 return nil, err
53 }
54 env := make(map[string]string)
55 if len(nwData) > 0 {
56 // Return proxy settings from the first interface that has an IPv4 address.
57 // The networks are in service order already.
58 var proxies sysprof.Proxies
59 for _, nw := range nwData {
60 if len(nw.IPv4.Addresses) > 0 {
61 proxies = nw.Proxies
62 break
63 }
64 }
65 // Proxies with a username are not going to work because the password is stored in a keychain.
66 // If users are fine with exposing the username/password, they can set the proxy to
67 // "http://username:[email protected]" in the system settings (or in lima.yaml).
68 if proxies.FTPEnable == "yes" && proxies.FTPUser == "" {
69 env["ftp_proxy"] = proxyURL(proxies.FTPProxy, proxies.FTPPort)
70 }
71 if proxies.HTTPEnable == "yes" && proxies.HTTPUser == "" {
72 env["http_proxy"] = proxyURL(proxies.HTTPProxy, proxies.HTTPPort)
73 }
74 if proxies.HTTPSEnable == "yes" && proxies.HTTPSUser == "" {
75 env["https_proxy"] = proxyURL(proxies.HTTPSProxy, proxies.HTTPSPort)
76 }
77 // Not setting up "no_proxy" variable; the values from the proxies.ExceptionList are
78 // not understood by most applications checking "no_proxy". The default value would
79 // be "*.local,169.254/16". Users can always specify env.no_proxy in lima.yaml.
80 }
81 return env, nil
82}