前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >powershell设置代理,$ENV:ALL_PROXY ='http://proxyserver_ip:proxyserver_port',不起作用

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

原创
作者头像
Windows技术交流
修改2024-04-26 15:01:32
2.6K0
修改2024-04-26 15:01:32
举报
文章被收录于专栏:Windows技术交流Windows技术交流
代码语言:javascript
复制
只对当前窗口有效
$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
复制
只对当前窗口有效
$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
复制
$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 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档