Free Website Monitor

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.


