Recently we were tasked with testing connectivity with Good For Enterprise servers. Since the environment is highly secure it requires proxy to go out. As we had to test connectivity on over 40 servers for multiple proxies and multiple URL's we had to find a simple, yet efficient way to do this.
After some quick scripting following script has shown to be very useful in this task.
# Proxy servers in format: https://<url>:<port>. Can be multiple Proxy servers used by comma separation $proxy_servers = "https://surf.proxy:8080";# , "https://server1.testproxy:8080"; # URL's to be tested thru Proxy. $urls = "https://xml28.good.com";, "https://xml29.good.com"; #,"https://xml30.good.com"; ,"https://gti01.good.com","https://www.good.com", "https://upl01.good.com", "https://ws.good.com"; # ComputerName of tested machine Write-Host "Testing script on machine: " $env:COMPUTERNAME function DoWork { # Test URL's without PROXY first foreach ($url in $urls) { TestWithoutProxy -URL $url } # Test URL's with Proxy foreach ($proxy_serv in $proxy_servers) { foreach ($url in $urls) { TestProxy -ProxyServer $proxy_serv -URL $url } } } function TestWithoutProxy { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [Alias("U")] [string]$url ) $WebClientWithoutProxy = New-Object System.Net.WebClient Write-Host -NoNewLine "Testing without proxy server " -ForegroundColor Yellow Write-Host -NoNewLine " [*] URL test without Proxy -" $url -ForegroundColor White Try { $contentWithouProxy = $WebClientWithoutProxy.DownloadString($url) Write-Host -NoNewline " [+] Opened $url successfully without Proxy" }catch { Write-Host -NoNewLine " [-] Unable to access $url without Proxy" -ForegroundColor Red } Write-Host " [*]" } function TestProxy { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [Alias("CN")][string[]]$ProxyServer, [Parameter(Position=1)] [Alias("U")] [string]$url ) $proxy = new-object System.Net.WebProxy($ProxyServer) $WebClient = new-object System.Net.WebClient $WebClient.proxy = $proxy #Write-Host "" Write-Host -NoNewLine "Testing proxy server: " $ProxyServer -ForegroundColor Yellow Write-Host -NoNewline " [*] URL test -" $url -ForeGroundColor White Try { $content = $WebClient.DownloadString($url) Write-Host -NoNewLine " [+] Opened $url successfully" -ForegroundColor Green "- Amount of chars found on website" $content.Length } catch { Write-Host -NoNewLine " [-] Unable to access $url" -ForegroundColor Red } Write-Host " [*]" } DoWork
Running it should give you a nice, quick overview of a test.
This post was last modified on March 20, 2016 12:24
Ever wondered how to run network diagnostics like Ping, Traceroute, or DNS queries from probes…
Are you tired of manually running network diagnostics like Ping, Traceroute, or DNS queries? The…
Discover new features in the PSWriteHTML PowerShell module – including New-HTMLInfoCard, improved layout controls with…
Security Identifier (SID) History is a useful mechanism in Active Directory (AD) migrations. It allows…
Today, I made the decision to upgrade my test environment and update the version of…
Have you ever looked at your Active Directory and wondered, "Why do I still have…