Updated Powershell Script to Test For Trace
This article has been superseded by this one.
No further updates will be made to this article.
In a previous post, I posted a basic powershell script that would test a site to see whether the TRACE method was enabled or not. I've updated that script so now you can test for other methods. Here is the updated script:
## USAGE: ./testURL.ps1 <http-method-to-test> <site-to-test-without-trailing-slash>
##
## Not sure why, but this script returns true if you use a URL like http://www.apache.org
## but fails if you use the correct URI syntax (http://www.apache.org/ << note trailing slash
param ($method,$url)
trap{
Write-Host $_
#clean up the current request
$request.Abort()
#an error occurred. ignore it and continue to returning false.
continue
}
$request = [System.Net.WebRequest]::Create($url)
$request.Method = $method
$request.TimeOut = 5000
if ($request.GetResponse().StatusCode -eq "OK")
{
#clean up the current request
$request.GetResponse().Close()
return $true
}
#should get here only if we got an error for our web request
return $false
Running the script is a matter of typing in the method you want to execute followed by the URL of the site you want to test: ".\testURLv2.ps1 %HTTPMETHOD% %URL%"
Enjoy! This script allows you to test to see if Methods like TRACK and OPTIONS work in additon to simply testing that the TRACE method works.