Question:
Problem
Our web host provider is changing the IP address of one of the servers we are on. We have been given a time frame for when the switch will take place, but no exact details. Therefore, our current poor man’s check requires a periodic page refresh on a browser to see if our website is still there.
Question
We are all programmers here and this is killing me that any manual checking is required. I would know how to do this in other languages, but want to know if there is a way to write a script in PowerShell to tackle this problem. Does anyone know how I might going about this?
Answer:
If you can alert if the page is gone or does not have an expected value, you could use a script like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ip = 192.168.1.1 $webclient = new-object System.Net.WebClient $regex = 'regular expression to match something on your page' $ping = new-object System.Net.NetworkInformation.Ping do { $result = $ping.Send($ip) if ($result.status -ne 'TimedOut' ) { $page = $webclient.downloadstring("http://$ip") if (($page -notmatch $regex) -or ($page -match '404') -or ($page -eq $null)) { break} } } while ($true) write-host "The website has moved" |