Monday, February 23, 2009

WebServer investigated

I recently spend some time playing around with creating a bunch of scripts to monitor changes in a web page. While doing this I needed to determine what kind of webserver a given site was hosted on. This is a somewhat simplified version of my solution:

function Get-WebServer {
    param ($target)
    if (-not ($target -like "http://*")) {
        $target = "http://" + $target
    $wr = [System.Net.WebRequest]::Create($target)
    $wr.UserAgent = "InterwebExploder 10.0 RC1 - 'Titanic'"
    $header = $wr.GetResponse()
    Write-host "$target"
    $header | select Server, LastModified, ProtocolVersion, ResponseUri | Format-List

Please note that proxies and various other issues can ruin the function.
To use the function, simply call it with the name of the target url:

Get-WebServer ""

No comments: