Internet watchdog

You would pus such code in the loop() because any communication issues (router restart etc.) will most likely happen when your sketch is running in the loop().

For developing and testing, it would be more convenient initially to have it in the setup(). Write a separate sketch for this.