Skip to content

Instantly share code, notes, and snippets.

@coldfusion39
Created April 8, 2016 13:11
Show Gist options
  • Save coldfusion39/d4714deca43c8f9dc840cb97f50e5fc7 to your computer and use it in GitHub Desktop.
Save coldfusion39/d4714deca43c8f9dc840cb97f50e5fc7 to your computer and use it in GitHub Desktop.
Test Windows proxy
#No Proxy
function NoProxy {
Param($URL);
$WC = New-Object Net.WebClient
$WC.DownloadString($URL)
}
#Proxy 1
function Proxy1 {
Param($URL);
$ProxyAddr = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
$Proxy = New-Object System.Net.WebProxy
$Proxy.Address = $ProxyAddr
$Proxy.useDefaultCredentials = $true
$WC = New-Object System.Net.WebClient
$WC.proxy = $Proxy
$WC.DownloadString($URL)
}
#Proxy 2
function Proxy2 {
Param($URL);
$Proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$Proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$WC = New-Object System.Net.WebClient
$WC.Proxy = $Proxy
$WC.DownloadString($URL)
}
#Proxy 3
function Proxy3 {
Param($URL);
$WC = New-Object Net.WebClient
$WC.UseDefaultCredentials = $true
$WC.Proxy.Credentials = $WC.Credentials
$WC.DownloadString($URL)
}
#Proxy4
function Proxy4 {
Param($URL);
$WC = New-Object System.Net.WebClient
$WC.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$WC.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$WC.DownloadString($URL)
}
$URL = ""
if (NoProxy $URL -ne $null) {
Write-Host "NoProxy works!"
} else {
Write-Host "NoProxy failed!"
}
if (Proxy1 $URL -ne $null) {
Write-Host "Proxy1 works!"
} else {
Write-Host "Proxy1 failed!"
}
if (Proxy2 $URL -ne $null) {
Write-Host "Proxy2 works!"
} else {
Write-Host "Proxy2 failed!"
}
if (Proxy3 $URL -ne $null) {
Write-Host "Proxy3 works!"
} else {
Write-Host "Proxy3 failed!"
}
if (Proxy4 $URL -ne $null) {
Write-Host "Proxy4 works!"
} else {
Write-Host "Proxy4 failed!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment