Résolu Problème Network Checker

Wazyx YT

Youtuber et Glitcher
Premium
Inscription
2 Février 2014
Messages
793
Réactions
681
Points
6 096
RGCoins
25
Salut tout le monde !
Je cherche un moyen de faire une petite app très simple pour checker en direct si ma connexion fonctionne ou non (j'ai quelques déco de temps en temps et je souhaiterait avoir un retour direct sur mon écran, simplement visuel).
Sauf que je ne trouve pas le moyen de le faire, j'ai déjà essayer de faire ça (je souahite ouvrir une appli qui, après avoir appuyé sur un bouton check continuellement si je suis connecté) :

Code:
private void metroButton1_Click(object sender, EventArgs e)
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                metroProgressBar1.Value = 100;
            }
            else
            {
                metroProgressBar1.Value = 10;
            }
        }
Code:
try
            {
                
                Ping myPing = new Ping();
                String host = "8.8.8.8";
                byte[] buffer = new byte[32];
                int timeout = 1000;
                PingOptions pingOptions = new PingOptions();
                PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
            }
            catch
            {
                metroProgressBar1.Value = 0;
                metroButton1.PerformClick();
            }
            finally
            {
                metroProgressBar1.Value = 100;
                metroProgressBar1.PerformClick;
            }
    
        }

Je suis vraiment nouveau dans ce domaine, je cherche juste à faire 2-3 truc pour commencer.
 
Sa doit suffire non ?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation; //Include this

namespace PingProto
{
    public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Ping myPing = new Ping();
                PingReply reply = myPing.Send("192.168.1.3", 1000);
                if (reply != null)
                {
                     Console.WriteLine("Status :  " + reply.Status + " \n Time : " + reply.RoundtripTime.ToString() + " \n Address : " + reply.Address);
                    //Console.WriteLine(reply.ToString());

                }
            }
            catch
            {
                Console.WriteLine("ERROR: You have Some TIMEOUT issue");
            }
             Console.ReadKey();
        }
    }
}
 
Cette réponse a aidé l'auteur de cette discussion !
Code:
bool Check = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

       if (Check == true)
           MessageBox.Show("OK!");
       else
           MessageBox.Show("Error!");
Merci mais en fait je cherche à voir si ma connexion est fonctionnelle, avec cette fonction, si je suis connecté à un réseau wifi mais où internet ne fonctionne pas, j'aurai un message comme quoi tout fonctionne. De plus j'aimerai lancer l'app une fois et que ça check tout les x temps par exemple.
 
Sa doit suffire non ?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation; //Include this

namespace PingProto
{
    public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Ping myPing = new Ping();
                PingReply reply = myPing.Send("192.168.1.3", 1000);
                if (reply != null)
                {
                     Console.WriteLine("Status :  " + reply.Status + " \n Time : " + reply.RoundtripTime.ToString() + " \n Address : " + reply.Address);
                    //Console.WriteLine(reply.ToString());

                }
            }
            catch
            {
                Console.WriteLine("ERROR: You have Some TIMEOUT issue");
            }
             Console.ReadKey();
        }
    }
}
Merci ! Je vais essayer de faire ça avec une interface, merci !
 
Retour
Haut