首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >powershell设置代理,$ENV:ALL_PROXY ='http://proxyserver_ip:proxyserver_port',不起作用

powershell设置代理,$ENV:ALL_PROXY ='http://proxyserver_ip:proxyserver_port',不起作用

原创
作者头像
Windows技术交流
修改2025-05-20 10:28:49
修改2025-05-20 10:28:49
5.3K00
代码可运行
举报
文章被收录于专栏:Windows技术交流Windows技术交流
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
复制
只对当前窗口有效
$proxyUrl = "http://proxyserver_ip:proxyserver_port"
$proxy = New-Object System.Net.WebProxy
$proxy.Address = $proxyUrl
[System.Net.WebRequest]::DefaultWebProxy = $proxy
列出代理
[System.Net.WebRequest]::DefaultWebProxy
验证效果
(Invoke-WebRequest 'http://ipinfo.io/ip' -UseBasicParsing).Content
(Invoke-WebRequest 'http://whatismyip.akamai.com' -UseBasicParsing).Content
#(Invoke-WebRequest 'http://ifconfig.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://ident.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://v4.ident.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://ip.gs' -UseBasicParsing).Content

代码语言:javascript
代码运行次数:0
运行
复制
只对当前窗口有效
$proxyUrl = "http://proxyserver_ip:proxyserver_port"
$ENV:HTTP_PROXY = $proxyUrl
$ENV:HTTPS_PROXY = $proxyUrl
列出代理
ls env:*|findstr PROXY
验证效果
$proxyUrl = "http://proxyserver_ip:proxyserver_port"
Invoke-WebRequest -Uri "http://example.com" -Proxy $proxyUrl

(Invoke-WebRequest 'http://ipinfo.io/ip' -UseBasicParsing -Proxy $proxyUrl).Content
(Invoke-WebRequest 'http://whatismyip.akamai.com' -UseBasicParsing -Proxy $proxyUrl).Content
#(Invoke-WebRequest 'http://ifconfig.me' -UseBasicParsing -Proxy $proxyUrl).Content
(Invoke-WebRequest 'http://ident.me' -UseBasicParsing -Proxy $proxyUrl).Content
(Invoke-WebRequest 'http://v4.ident.me' -UseBasicParsing -Proxy $proxyUrl).Content
(Invoke-WebRequest 'http://ip.gs' -UseBasicParsing -Proxy $proxyUrl).Content

清空代理
$ENV:HTTP_PROXY=""
$ENV:HTTPS_PROXY=""
ls env:*|findstr PROXY

图形界面设置代理:

运行inetcpl.cpl → 连接 → 局域网设置 → 代理服务器(地址和端口)

代码语言:javascript
代码运行次数:0
运行
复制
$proxyServer = "proxyserver_ip:proxyserver_port"
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

# Proxy Enable : Set 'ProxyEnable' to 1 to enable proxy, set 0 to disable proxy
Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 1

# Proxy Server : Set 'ProxyServer' to your proxy address and port (e.g., "192.168.1.1:8080")
Set-ItemProperty -Path $registryPath -Name ProxyServer -Value $proxyServer

# Apply proxy settings to all protocols: remove any exceptions that may exist
Set-ItemProperty -Path $registryPath -Name ProxyOverride -Value ""

列出代理
[System.Net.WebProxy]::GetDefaultProxy()
Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | Select-Object ProxyServer, ProxyEnable
验证效果
(Invoke-WebRequest 'http://ipinfo.io/ip' -UseBasicParsing).Content
(Invoke-WebRequest 'http://whatismyip.akamai.com' -UseBasicParsing).Content
(Invoke-WebRequest 'http://ifconfig.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://ident.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://v4.ident.me' -UseBasicParsing).Content
(Invoke-WebRequest 'http://ip.gs' -UseBasicParsing).Content


临时禁止代理:
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' ProxyEnable -value 0
临时启用代理:
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' ProxyEnable -value 1


彻底干掉代理:
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' ProxyEnable -value 0
$proxyServer = ""
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $registryPath -Name ProxyServer -Value $proxyServer
Set-ItemProperty -Path $registryPath -Name ProxyOverride -Value ""

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档