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 = "[email protected]"
                 $emailTo = "[email protected]"
                 $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.

Most Commented Post

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear