You can use NetworkInterface.GetIsNetworkAvailable
method which indicates whether any network connection is available.
Try this:
bool connection = NetworkInterface.GetIsNetworkAvailable();
if (connection == true)
{
MessageBox.Show("The system is online");
}
else {
MessageBox.Show("The system is offline";
}