惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

Walk on 轻风云

暂无文章

golang实现windows下切换代理
2021-05-12 · via Walk on 轻风云

golang实现windows下切换代理

实现很简单 主要修改注册表文件 利用walk展示页面

界面如下

img

img

 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main

import (
    "github.com/lxn/walk"
    . "github.com/lxn/walk/declarative"
    "github.com/lxn/win"
    "golang.org/x/sys/windows/registry"
    "log"
)

func main() {

    var mw *walk.MainWindow
    var inTE *walk.TextEdit

    if err := (MainWindow{
        AssignTo: &mw,
        //Icon:     "img/logo.ico",
        Title:  "代理",
        Size:   Size{300, 200},
        Layout: VBox{},
        Children: []Widget{
            HSplitter{
                Children: []Widget{
                    TextEdit{AssignTo: &inTE, ReadOnly: true},
                },
            },
            PushButton{
                Text: "连接",
                OnClicked: func() {
                    status, ip := start()
                    if status {
                        inTE.SetText("连接成功\n当前IP" + ip)
                    } else {
                        inTE.SetText("连接失败")
                    }

                },
            },
            PushButton{
                Text: "关闭",
                OnClicked: func() {
                    status := editReg("0", "")
                    if status {
                        inTE.SetText("连接已关闭")
                    } else {
                        inTE.SetText("关闭失败")
                    }
                },
            },
        },
    }.Create()); err != nil {
        log.Fatal(err)
    }

    win.SetWindowLong(mw.Handle(), win.GWL_STYLE, win.GetWindowLong(mw.Handle(), win.GWL_STYLE) & ^win.WS_MAXIMIZEBOX & ^win.WS_THICKFRAME)

    mw.Run()

}

func start() (bool, string) {
    ip, port := getIp()
    status := editReg("1", ip+":"+port)
    return status, ip
}

// 获取ip
func getIp() (string, string) {
    // 自行获取ip
    return "183.88.226.50", "8080"
}

func editReg(enable, proxy string) bool {
    key, exists, err := registry.CreateKey(registry.CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", registry.ALL_ACCESS)
    if err != nil {
        log.Fatal(err)
    }
    defer key.Close()

    if !exists {
        return false
    }

    err = key.SetStringValue("ProxyEnable", enable)
    if err != nil {
        return false
    }

    err = key.SetStringValue("ProxyServer", proxy)
    if err != nil {
        return false
    }

    return true
}