This repository was archived by the owner on Jun 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy_windows.go
More file actions
67 lines (55 loc) · 1.41 KB
/
Copy pathproxy_windows.go
File metadata and controls
67 lines (55 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package sysproxy
import (
"fmt"
"strconv"
"strings"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
var (
procGetProxy *syscall.LazyProc
)
func init() {
// Ref: https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser
procGetProxy = syscall.NewLazyDLL("winhttp.dll").NewProc("WinHttpGetIEProxyConfigForCurrentUser")
}
// Ref: https://learn.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_current_user_ie_proxy_config
type rawProxyConfig struct {
autoDetect bool
autoConfigUrl *uint16
proxy *uint16
proxyBypass *uint16
}
func GetHTTP() (*Info, error) {
var c rawProxyConfig
r1, _, err := procGetProxy.Call(uintptr(unsafe.Pointer(&c)))
if r1 == 0 {
return nil, fmt.Errorf("cannot get IE proxy config: %w", err)
}
proxyURL := windows.UTF16PtrToString(c.proxy)
if proxyURL == "" {
return nil, nil
}
part := strings.SplitN(proxyURL, ":", 2)
if len(part) != 2 {
return nil, fmt.Errorf("invalid proxy URL format: %s", proxyURL)
}
host := part[0]
port, err := strconv.ParseUint(part[1], 10, 32)
if err != nil {
return nil, err
}
return &Info{
Host: host,
Port: uint16(port),
}, nil
}
func GetHTTPS() (*Info, error) {
return nil, nil
}
// GetAll Get Windows proxy information. Windows proxy settings only support http proxy.
func GetAll() (*Info, *Info, error) {
http, err := GetHTTP()
return http, nil, err
}