Free Website Monitor

G07L0063

I have over 100 websites now and the danger exists that one of them might get hacked.

This wouldn’t be a big problem if I knew about it.  I have backups in place.

But how do you keep track of 100 web sites so that you know if one or more have been hacked so you can do something about it?

Obviously, you need some kind of site monitoring software.  I don’t need anything elaborate.  Just go look at the website and make sure it still has my content.

I found one that does just that, and it was free, but when I went to add my second site, I couldn’t get it to work.  It couldn’t see the text on the page that was clearly there.

That’s when I thought to myself, “I bet this is something I could get PowerShell to do for me easily enough.”  And sure enough, a search on the web turned up this script:

Quick And Dirty Website Monitoring With Powershell

Then I decided I should make sure that my router was up, so I went looking for a ping script that I could adapt.  I used this one:

PowerShell To Ping Range of IP Addresses

The result is my own script that looks like this:

    $ping = New-Object System.Net.NetworkInformation.Ping
    $ip = "192.168.0.1";

    $res = $ping.send($ip)
    if($res.Status -eq "Success")
    {

        # Create the variables
        $global:GArgs = $Args

        $urlsToTest = @{}
        $urlsToTest["domain1"] = "http://somedomain.com"
        $urlsToTest["domain2"] = "http://someotherdomain.com"

        $successCriteria = @{}
        $successCriteria["domain1"] = "*text to search in somedomain.com*"
        $successCriteria["domain2"] = "*text to search in someotherdomain.com*"

        $userAgent = "PowerShell User"
        $webClient = new-object System.Net.WebClient
        $webClient.Headers.Add("user-agent", $userAgent)

        foreach ($key in $urlsToTest.Keys) {
           $output = ""

           $startTime = get-date
           $output = $webClient.DownloadString($urlsToTest[$key])
           $endTime = get-date

           if ($output -like $successCriteria[$key]) {
              $key + "`t`tSuccess`t`t" + $startTime.DateTime + "`t`t" + `                   ($endTime - $startTime).TotalSeconds + " seconds"

              if ($GArgs -eq "-log") {
                 $key + "`t`tSuccess`t`t" + $startTime.DateTime + "`t`t" + `                   ($endTime - $startTime).TotalSeconds + " seconds" >> WebSiteTest.log
              }
           } else {
              $key + "`t`tFail`t`t" + $startTime.DateTime + "`t`t" + `                   ($endTime - $startTime).TotalSeconds + " seconds"

              if ($GArgs -eq "-log") {
                 $key + "`t`tFail`t`t" + $startTime.DateTime + "`t`t" + `                   ($endTime - $startTime).TotalSeconds + " seconds" >> WebSiteTest.log
              }

                 $emailFrom = "fromemail@fromemail.com"
                 $emailTo = "toemail@toemail.com"
                 $subject = "URL Test Failure - " + $startTime
                 $body = "URL Test Failure: " + $key + " (" + `                    $urlsToTest[$key] + ") at " + $startTime
                 $smtpServer = "smtp.domain.com"
                 $smtp = new-object Net.Mail.SmtpClient($smtpServer)
                 $smtp.Send($emailFrom,$emailTo,$subject,$body)

           }
        }
    }

Then I just schedule the script in the Windows scheduler and it monitors my web sites for me.

Related Post

  • Synergy – The Virtual KVM (sort of)Synergy – The Virtual KVM (sort of) This afternoon (last Thursday by the time this actually goes live) one of my clients introduced me to Synergy.  This is one of the coolest tools I've seen since VNC. Now, to be […]
  • Upgrading Vista 32 bit to Windows 7 64bitUpgrading Vista 32 bit to Windows 7 64bit Since I own an MSDN subscription, I was able to get my hands on a copy of Windows 7 last Thursday. I didn’t actually install it until this past Sunday because Sunday is the only day I […]
  • Paging on a DatalistPaging on a Datalist This morning, my email had the following question: “I am having a problem with datalist. Is it possible to do paging on datalist? If yes, what is the solution? I am using VB.NET on […]
  • SQL Express Mixed Mode AuthenticationSQL Express Mixed Mode Authentication So, I'm getting ready to do some data binding demos and I realized that when I installed Visual Studio, I forgot to install SQL Server Express first so that I could control the […]
  • WordPress w/ Forms Authentication on IIS6WordPress w/ Forms Authentication on IIS6 I know I said yesterday that I'd start a series about creating DotNetNuke modules, but I solved a problem yesterday after I wrote that post that I think a lot of you will be interested […]

About Dave Bush

Dave Bush is a .NET programmer and Certified ScrumMaster who is passionate about managing risk as it relates to developing software. When he is not writing or speaking about topics related to Application Lifecycle Risk Management (ALRM), he is an example to his peers as he develops web sites in the ASP.NET environment using industry best practices.

Awards & Certs