gosysproxy

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 6 Imported by: 2

README

Go System Proxy Windows系统代理配置

Documentation GitHub go.mod Go version

通过系统调用的方式实现Windows系统的代理配置、状态查询。

Quick Start

获取

go get -u github.com/Trisia/gosysproxy

API

// SetPAC 设置PAC代理模式
// scriptLoc: 脚本地址,如: "http://127.0.0.1:7777/pac"
func SetPAC(scriptLoc string)

// SetGlobalProxy 设置全局代理
// proxyServer: 代理服务器host:port,例如: "127.0.0.1:7890"
// bypass: 忽略代理列表,这些配置项开头的地址不进行代理
func SetGlobalProxy(proxyServer string, bypasses ...string) error

// Off 关闭代理
func Off() error

// Flush 更新系统配置使生效
func Flush()

// Status 获取当前系统代理配置
func Status() (*ProxyStatus, error)

详见: 《Go System Proxy 接口文档》

Demo

package main

import (
	"github.com/Trisia/gosysproxy"
	"time"
)

func main() {
    // 设置全局代理
    err := gosysproxy.SetGlobalProxy("127.0.0.1:7890")
    if err{
        panic(err)
    }
    
    time.Sleep(time.Second * 60)
    
    err := gosysproxy.Off()
    if err{
        panic(err)
    }
}

完整示例详见: main_test.go

致谢

Documentation

Rendered for windows/amd64

Overview

windows系统代理配置

Index

Constants

View Source
const (
	INTERNET_OPEN_TYPE_PRECONFIG = 0 // use registry configuration
	INTERNET_OPEN_TYPE_DIRECT    = 1 // 禁用代理 direct to net
	INTERNET_OPEN_TYPE_PROXY     = 3 // 启用代理 via named proxy
)

Variables

This section is empty.

Functions

func Flush

func Flush() error

Flush 更新系统配置使生效

func Off

func Off() error

Off 关闭代理

func SetGlobalProxy

func SetGlobalProxy(proxyServer string, bypasses ...string) error

SetGlobalProxy 设置全局代理 - proxyServer: 代理服务器 host:port,例如: "127.0.0.1:7890" - bypass: 忽略代理列表,这些配置项开头的地址不进行代理,若包含 "<local>" 则 ”请勿将代理服务器用于本地(Intranet)地址“ 将勾选。

func SetPAC

func SetPAC(scriptLoc string) error

SetPAC 设置PAC代理模式 scriptLoc: 脚本地址,如: "http://127.0.0.1:7777/pac"

Types

type ProxyStatus

type ProxyStatus struct {
	// 代理类型
	// - 0: INTERNET_OPEN_TYPE_PRECONFIG: use registry configuration
	// - 1: INTERNET_OPEN_TYPE_DIRECT: 不代理 direct to net
	// - 3: INTERNET_OPEN_TYPE_PROXY: 使用代理服务器 via named proxy
	Type  uint32
	Proxy string // 代理IP地址与端口,IP:Port,例如:"127.0.0.1:7890"
	// 请勿对以下列条目开头的地址使用代理服务器
	// 注意:
	// - 这里的地址是ASCII编码
	// - "<local>" 表示 本地(Intranet)地址,如果包含 "<local>" 则 DisableProxyIntranet 为 true
	//
	// 例如:["localhost","127.*"],
	Bypass               []string
	DisableProxyIntranet bool // 请勿将代理服务器用于本地(Intranet)地址
}

func Status

func Status() (*ProxyStatus, error)

Status 获取当前系统代理配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL