代码语言: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:SoftwareMicrosoftWindowsCurrentVersionInternet 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:SoftwareMicrosoftWindowsCurrentVersionInternet 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:SoftwareMicrosoftWindowsCurrentVersionInternet Settings' ProxyEnable -value 0
临时启用代理:
Set-ItemProperty -Path 'HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings' ProxyEnable -value 1
彻底干掉代理:
Set-ItemProperty -Path 'HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings' ProxyEnable -value 0
$proxyServer = ""
$registryPath = "HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings"
Set-ItemProperty -Path $registryPath -Name ProxyServer -Value $proxyServer
Set-ItemProperty -Path $registryPath -Name ProxyOverride -Value ""