Bonjour,

En bref mon code envoie une succession de ping et regarde à la volée les réponses.
J'ai besoin de faire une pause dans mon programme pour arrêter l'envie des ping mais il doit continuer de lire les réponses.
Du coup si j'utilise :
Il arrête les deux. Comment faire pour stopper seulement les envois ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading;
 
namespace MultiPing
{
    class Program
    {
        static void Main(string[] args)
        {
            string Network = "10.240.0.0/15";
            //string motACouper = "/";
            //string[] chaineArrive = Network.Split(new string[] { motACouper }, StringSplitOptions.None);
            string[] chaineArrive = Network.Split('/');
            int masque = Convert.ToInt32(chaineArrive[1]);
            //string[] TabOctes = Network.Split(new string[] { chaineArrive[0] }, StringSplitOptions.None);
            string[] TabOctes = chaineArrive[0].Split('.');
            int Octet1 = Convert.ToInt32(TabOctes[0]);
            int Octet2 = Convert.ToInt32(TabOctes[1]);
            int Octet3 = Convert.ToInt32(TabOctes[2]);
            int Octet4 = Convert.ToInt32(TabOctes[3]);
            string Octet1Bin = Convert.ToString(Octet1, 2);
            Octet1Bin = Octet1Bin.PadLeft(8, '0');
            string Octet2Bin = Convert.ToString(Octet2, 2);
            Octet2Bin = Octet2Bin.PadLeft(8, '0');
            string Octet3Bin = Convert.ToString(Octet3, 2);
            Octet3Bin = Octet3Bin.PadLeft(8, '0');
            string Octet4Bin = Convert.ToString(Octet4, 2);
            Octet4Bin = Octet4Bin.PadLeft(8, '0');
            int Octet1Debut;
            int Octet1Fin;
            int Octet2Debut;
            int Octet2Fin;
            int Octet3Debut;
            int Octet3Fin;
            int Octet4Debut;
            int Octet4Fin;
            if(masque >24)       // modifie octect 4
            {
                char[] Octet4BinGlobal = Octet4Bin.ToCharArray();
                char[] Octect4BinBroadcast = Octet4Bin.ToCharArray();
                int masqueOctet =8-( 32 - masque);
                for(int a=0;a<8;a++)
                {
                    if (a >( masqueOctet-1))
                    {
                        Octet4BinGlobal[a] = '0';
                        Octect4BinBroadcast[a] = '1';
                    }
                }
 
                Octet1Debut=Octet1;
                Octet1Fin=(Octet1+1);
                Octet2Debut=Octet2;
                Octet2Fin=(Octet2+1);
                Octet3Debut=Octet3;
                Octet3Fin=(Octet3+1);
                string Octet4Globalstr = new string(Octet4BinGlobal);
                Octet4Debut = Convert.ToInt32(Octet4Globalstr, 2);
                string Octet4Broadcaststr = new string(Octect4BinBroadcast);
                Octet4Fin = (Convert.ToInt32(Octet4Broadcaststr, 2)+1);
            }
            else if(masque >16)  //modifie octect 3
            {
                Console.WriteLine("je modifie l'octet 3");
                char[] Octet3BinGlobal = Octet3Bin.ToCharArray();
                char[] Octect3BinBroadcast = Octet3Bin.ToCharArray();
                int masqueOctet = 8-(24 - masque);
                for (int a = 0; a < 8; a++)
                {
                    if (a > (masqueOctet-1))
                    {
                        Octet3BinGlobal[a] = '0';
                        Octect3BinBroadcast[a] = '1';
                    }
                }
                Octet1Debut = Octet1;
                Octet1Fin = (Octet1+1);
                Octet2Debut = Octet2;
                Octet2Fin = (Octet2+1);
                string Octet3Globalstr = new string(Octet3BinGlobal);
                Octet3Debut = Convert.ToInt32(Octet3Globalstr, 2);
                string Octet3Broadcaststr = new string(Octet3BinGlobal);
                Octet3Fin = (Convert.ToInt32(Octet3Broadcaststr, 2)+1); 
                Octet4Debut = 0;
                Octet4Fin = 256;
            }
            else if(masque >8)  // modifie octect 2
            {
                char[] Octet2BinGlobal = Octet2Bin.ToCharArray();
                char[] Octect2BinBroadcast = Octet2Bin.ToCharArray();
                int masqueOctet = 8-(16 - masque);
                for (int a = 0; a < 8; a++)
                {
                    if (a > (masqueOctet-1))
                    {
                        Octet2BinGlobal[a] = '0';
                        Octect2BinBroadcast[a] = '1';
                    }
                }
 
                int Octet3Global = 
                Octet1Debut = Octet1;
                Octet1Fin =( Octet1 +1);
                string Octet2Globalstr = new string(Octet2BinGlobal);
                Octet2Debut = Convert.ToInt32(Octet2Globalstr, 2);
                string Octet2Broadcaststr = new string(Octect2BinBroadcast);
                Octet2Fin =( Convert.ToInt32(Octet2Broadcaststr, 2)+1);
                Octet3Debut = 0;
                Octet3Fin = 256;
                Octet4Debut = 0;
                Octet4Fin = 256;
            }
            else               // modifie octect 1
            {
                char[] Octet1BinGlobal = Octet1Bin.ToCharArray();
                char[] Octect1BinBroadcast = Octet1Bin.ToCharArray();
                int masqueOctet =8-( 8 - masque);
                for (int a = 0; a < 8; a++)
                {
                    if (a > (masqueOctet-1))
                    {
                        Octet1BinGlobal[a] = '0';
                        Octect1BinBroadcast[a] = '1';
                    }
                }
                string Octet1Globalstr = new string(Octet1BinGlobal);
                Octet1Debut = Convert.ToInt32(Octet1Globalstr, 2);
                string Octet1Broadcaststr = new string(Octect1BinBroadcast);
                Octet1Fin = (Convert.ToInt32(Octet1Broadcaststr, 2)+1);
                Octet2Debut = 0;
                Octet2Fin = 256;
                Octet3Debut = 0;
                Octet3Fin = 256;
                Octet4Debut = 0;
                Octet4Fin = 256;
            }
            SendMultiPing(Octet1Debut,Octet1Fin,Octet2Debut,Octet2Fin,Octet3Debut,Octet3Fin,Octet4Debut,Octet4Fin);
        }
 
        private static void SendMultiPing(int a,int ab,int b,int bb,int c,int cb,int d,int db)
        {
            int i = 0;
            string address;
            //int i = 0;
            for (int w = a; w < ab; w++)
            {
                for (int x = b; x < bb; x++)
                {
                    for (int y = c; y < cb; y++)
                    {
 
                        for (int z = d; z < db; z++)
                        {
                            address = "10." + Convert.ToString(x) + "." + Convert.ToString(y) + "." + Convert.ToString(z);
                            Ping pong = new Ping();
                            pong.PingCompleted += PingCompleted;
                            pong.SendAsync(address, new byte[32]);
                            i++;
                            if(i > 5000)
                            {
                                Console.WriteLine("pause");
                                i = 0;
                                //for(int v=0;v<90000000;v++)
                                //{
                                    //attend les reponse pour les suprimé et faire de la place
 
                                //}
                                Thread.Sleep(5000);
                                Console.WriteLine("Fin Pause");
                            }
                        }
                    }
 
                }
            }
        }
 
        private static void PingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (e.Reply.Status == IPStatus.Success)
            {
                Console.WriteLine(e.Reply.Address.ToString());
                ((Ping)sender).PingCompleted -= PingCompleted;
            }
            if(e.Reply.Status==IPStatus.TimedOut)
            {
                //kill the instance classe
                ((Ping)sender).PingCompleted -= PingCompleted;
            }
 
        }
    }
}
Merci.