Checks network connectivity and acts accordingly.