如何在 PowerShell 中使用代理

2020 年 6 月 21 日 星期日(已编辑)
/ ,
12

如何在 PowerShell 中使用代理

2022-04-12 更新

在网上看到了一个用在 WSL 上的方法

~/.bashrc 中添加以下内容:

# 我自己用的
export hostip=$(ip addr show eth2 | grep 'inet ' | cut -f 6 -d ' ' | cut -f 1 -d '/')
# 原文章的写法
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
alias proxy='
    export https_proxy="socks5://${hostip}:7890";
    export http_proxy="socks5://${hostip}:7890";
    export all_proxy="socks5://${hostip}:7890";
    echo -e "Acquire::http::Proxy \"http://${hostip}:7890\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
    echo -e "Acquire::https::Proxy \"http://${hostip}:7890\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias unproxy='
    unset https_proxy;
    unset http_proxy;
    unset all_proxy;
    sudo sed -i -e '/Acquire::http::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
    sudo sed -i -e '/Acquire::https::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
'

输入 source ~/.bashrc 应用代理

2021-10-12 更新

感觉直接添加环境变量更方便一些

HTTP_PROXY = "http://127.0.0.1:port"
HTTPS_PROXY = "http://127.0.0.1:port"

不多说,直接给代码吧

添加/编辑代理
Set-Item Env:http_proxy = "http://127.0.0.1:port"
删除代理
Set-Item Env:http_proxy

使用社交账号登录

  • Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...