系统代理

2019/10/08 技术

系统代理

1. mac 系统

1.1 terminal 设置代理

~/.bash_profile 中添加设置

alias proxytest='curl http://pv.sohu.com/cityjson?ie=utf-8'
deproxy () { 
    unset https_proxy
    unset http_proxy
    echo "clear proxy!"
}

acproxy (){
    _proxy="http://localhost:8118"
    export https_proxy=$_proxy
    export http_proxy=$_proxy
    echo "using proxy: $_proxy!"
}

使用示例:

# 设置前
proxytest

# 设置代理
acproxy
proxytest

# 取消代理
deproxy
proxytest

1.2 全局设置代理

~/.bash_profile 中添加设置

# global proxy
acglobalproxy () {                                                                                                                                                         
    sudo networksetup -setwebproxy "Wi-Fi" 127.0.0.1 8118
    sudo networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 8118
    sudo networksetup -setsocksfirewallproxy "Wi-Fi" 127.0.0.1 1080
}
deglobalproxy () {
    sudo networksetup -setwebproxy "Wi-Fi" "" ""
    sudo networksetup -setwebproxystate "Wi-Fi" off
    sudo networksetup -setsecurewebproxy "Wi-Fi" "" ""
    sudo networksetup -setsecurewebproxystate "Wi-Fi" off
    sudo networksetup -setsocksfirewallproxy "Wi-Fi" "" ""
    sudo networksetup -setsocksfirewallproxystate "Wi-Fi" off
}

使用示例:

# 设置前
proxytest

# 设置代理
acglobalproxy
proxytest

# 取消代理
deglobalproxy
proxytest

Search

    Table of Contents