示例#1
0
文件: async.cs 项目: mono/gert
	public static void PingCompletedCallback (object sender, PingCompletedEventArgs e)
	{
		// If the operation was canceled, display a message to the user.
		if (e.Cancelled) {
			Console.WriteLine ("Ping canceled.");

			// Let the main thread resume. 
			// UserToken is the AutoResetEvent object that the main thread 
			// is waiting for.
			((AutoResetEvent) e.UserState).Set ();
		}

		// If an error occurred, display the exception to the user.
		if (e.Error != null) {
			Console.WriteLine ("Ping failed:");
			Console.WriteLine (e.Error.ToString ());

			// Let the main thread resume. 
			((AutoResetEvent) e.UserState).Set ();
		}

		PingReply reply = e.Reply;

		DisplayReply (reply);

		// Let the main thread resume.
		((AutoResetEvent) e.UserState).Set ();
	}
示例#2
0
	private void HandleConnectionPingCompleted(object sender, PingCompletedEventArgs e)
	{
		if (m_TcpClient != null)
		{
			Disconnect();
		}
		m_TcpClient = new TcpClient();
		m_TcpClient.BeginConnect(Hostname, Port, ConnectComplete, null);
	}
示例#3
0
        /// <summary>
        /// Ping complete event.
        /// </summary>
        /// <param name="sender">Current sender.</param>
        /// <param name="e">Event arguments.</param>
        void OnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            // Check to see if an error occurred.  If no error, then display
            // the address used and the ping time in milliseconds.
            if (e.Error == null)
            {
                // If the operation was cancelled.
                if (e.Cancelled)
                {
                    txtPingResult.Text += "  Ping cancelled. \r\n";
                }
                else
                {
                    // If the ping request succeded.
                    if (e.Reply.Status == IPStatus.Success)
                    {
                        // Show the result of the
                        // ping request.
                        txtPingResult.Text +=
                            "  " + e.Reply.Address.ToString() + " " +
                            e.Reply.RoundtripTime.ToString(
                                NumberFormatInfo.CurrentInfo) + "ms" + "\r\n";
                    }
                    else
                    {
                        // If the ping was not succesful
                        // then get ip status.
                        txtPingResult.Text +=
                            "  " + GetStatusString(e.Reply.Status) + "\r\n";
                    }
                }
            }
            else
            {
                // Otherwise display the error.
                txtPingResult.Text += "  Ping error.\r\n";
                MessageBox.Show("An error occurred while sending this ping. " +
                                e.Error.InnerException.Message);
            }

            // Enable the send ping button
            // when the ping was complete.
            btnPing.Enabled = true;
        }
示例#4
0
        private void PingCompleted(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;

            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                string   hostname = GetHostName(ip);
                string[] arr      = new string[3];

                arr[0] = ip;
                arr[1] = hostname;

                if (!containsValue(ips, arr[0]))
                {
                    ips.Add(arr[0]);
                    ids.Add(arr[1]);
                }
            }
        }
示例#5
0
        private void myPingCompletedCallBack(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                if (notifyIcon1.Visible == true)
                {
                    notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\circle_red.ico");
                }
                else
                {
                    lblStatus.Text  = "Offline";
                    picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\red.png");
                    online          = false;
                }
            }

            if (e.Reply.Status == IPStatus.Success)
            {
                if (notifyIcon1.Visible == true)
                {
                    notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\btn_green.ico");
                }
                else
                {
                    lblStatus.Text  = "Online";
                    picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\green_ball.png");
                    online          = true;
                }
            }
            else
            {
                if (notifyIcon1.Visible == true)
                {
                    notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\btn_red.ico");
                }
                else
                {
                    lblStatus.Text  = "Offline";
                    picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\red.png");
                    online          = false;
                }
            }
        }
        private void OnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (PingReplies.Count() > MaxReply)
            {
                Dispatcher.Invoke(() => PingReplies.RemoveAt(PingReplies.Count - 1));
            }

            LastReply = new PingReplyWrapper(e.Reply);
            Dispatcher.Invoke(() => PingReplies.Insert(0, LastReply));

            CalculateAverage();
            CalculatePacketLoss();

            Task.Delay(PingInterval).ContinueWith(_ => { if (IsRunning)
                                                         {
                                                             StartPing();
                                                         }
                                                  });
        }
示例#7
0
        internal void PingComplete(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                ts.TraceInformation("Ping was canceled");
            }

            else if (e.Error != null)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "An error occured: {0}", e.Error);
                this.context.EvError();
            }

            else
            {
                PingReply pingResponse = e.Reply;
                ShowPingResults(pingResponse);
            }
        }
示例#8
0
        private void p_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            var ip = (string)e.UserState;

            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                string name;
                if (true)
                {
                    try
                    {
                        var hostEntry = Dns.GetHostEntry(ip);
                        name = hostEntry.HostName;
                    }
                    catch (SocketException)
                    {
                        name = "?";
                    }

                    _logger.Info($"{ip} ({name}) is up: ({e.Reply.RoundtripTime} ms)");
                }
                else
                {
                    _logger.Info($"{ip} is up: ({e.Reply.RoundtripTime} ms)");
                }

                Interlocked.Increment(ref _upCount);
                ReachableAdress.Add(new Host {
                    Ip = ip, Name = name, RoundtripTime = e.Reply.RoundtripTime
                });
            }
            else if (e.Reply == null)
            {
                _logger.Info($"Pinging {ip} failed. (Null Reply object?)");
            }

            var notify = _upCount % 10 == 0;

            if (notify || ip.EndsWith("254"))
            {
                OnPropertyChanged(nameof(ReachableAdress));
            }
        }
示例#9
0
        void pinger_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            try
            {
                object[] args    = (object[])e.UserState;
                DateTime time    = (DateTime)args[0];
                long     pingNum = (long)args[1];

                PingGraphControl graph = (PingGraphControl)args[2];
                int       pingTargetId = (int)args[3];           // Do not assume the pingTargets or pingGraphs containers will have this key!
                IPAddress remoteHost   = (IPAddress)args[4];
                Ping      pinger       = (Ping)args[5];
                pinger.PingCompleted -= pinger_PingCompleted;
                PingInstancePool.Recycle(pinger);
                if (e.Cancelled)
                {
                    graph.AddPingLogToSpecificOffset(pingNum, new PingLog(time, 0, IPStatus.Unknown));
                    Interlocked.Increment(ref failedPings);
                    return;
                }
                graph.AddPingLogToSpecificOffset(pingNum, new PingLog(time, (short)e.Reply.RoundtripTime, e.Reply.Status));
                if (e.Reply.Status != IPStatus.Success)
                {
                    Interlocked.Increment(ref failedPings);
                    if (clearedDeadHosts && pingTargets.ContainsKey(pingTargetId))
                    {
                        CreateLogEntry("" + time.ToString(dateFormatString) + ", " + remoteHost.ToString() + ": " + e.Reply.Status.ToString());
                    }
                }
                else
                {
                    if (!clearedDeadHosts)
                    {
                        pingTargetHasAtLeastOneSuccess[pingTargetId] = true;
                    }
                    Interlocked.Increment(ref successfulPings);
                }
            }
            finally
            {
                UpdatePingCounts(Interlocked.Read(ref successfulPings), Interlocked.Read(ref failedPings));
            }
        }
示例#10
0
        private void PingCompletedCallback(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                ((Ping)sender).PingCompleted -= PingCompletedCallback;
                return;
            }
            PingReply reply = e.Reply;

            DisplayReply((string)e.UserState, reply);
            ((Ping)sender).PingCompleted -= PingCompletedCallback;

            //speed.Plot1.InvalidatePlot(true);

            /*if (continuous) {
             * await Task.Delay(1000);
             * doPing((Ping)sender, ((string)e.UserState));
             * }*/
        }
示例#11
0
        private static void PingCompleted(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;

            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                string hostName   = GetHostName(ip);
                string macAddress = GetMacAddress(ip);

                var result = new PingResult()
                {
                    IP         = ip,
                    HostName   = hostName,
                    MacAddress = macAddress
                };

                Console.Out.WriteLine($"Ping Result: {ip} - {hostName} - {macAddress}");
            }
        }
示例#12
0
 private void pingTest_Complete(object sender, PingCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         MessageBox.Show("MadCow was unable to detect an active Internet connection." + "\nMadCow has an strong Internet dependency and wont work properly under this conditions.", "[FATAL ERROR] - No Internet Connection was found", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         PingReply pingResponse = e.Reply;
         if (pingResponse.Status == IPStatus.Success)
         {
             Console.WriteLine("Internet connectivity found.");
         }
         else
         {
             MessageBox.Show("MadCow was unable to detect an active Internet connection." + "\nMadCow has an strong Internet dependency and wont work properly under this conditions.", "[FATAL ERROR] - No Internet Connection was found", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
示例#13
0
 private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
 {
     if (e.Reply.Status == IPStatus.Success)
     {
         string reply = e.Reply.Address.ToString();
         if (computerInfo.Keys.Contains(reply))
         {
             try
             {
                 computerInfo[reply].machinename = Dns.GetHostEntry(IPAddress.Parse(reply)).HostName;
                 computerInfo[reply].status      = ComputerStatus.ON_LINE;
                 Kii.Invoke(computerInfo[reply]);
             }
             catch (Exception err)
             {
             }
         }
     }
 }
 private void Pinger_PingCompleted(object sender, PingCompletedEventArgs e)
 {
     try
     {
         if (e.Reply != null)
         {
             chart1.AddPoint(e.Reply.Status);
         }
         else
         {
             chart1.AddPoint(IPStatus.BadDestination);
         }
         pinger.SendAsyncCancel();
     }
     catch (Exception error)
     {
         Console.WriteLine("void Pinger_PingCompleted error: " + error.Message);
     }
 }
示例#15
0
        /// <summary>
        /// Called when ping completed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The
        /// <see cref="System.Net.NetworkInformation.PingCompletedEventArgs"/>
        /// instance containing the event data.</param>
        private void OnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (!e.Cancelled)
            {
                if (e.Reply.Status != IPStatus.Success)
                {
                    SynchronizationContext syncContext = e.UserState as SynchronizationContext;
                    syncContext.Post(
                        state =>
                    {
                        this.errors[Reflect.GetPropertyName(() => this.IpAddress)] =
                            string.Format(Resources.PingFailed, e.Reply.Status.ToString());

                        this.OnPropertyChanged(Reflect.GetPropertyName(() => this.IpAddress));
                    },
                        null);
                }
            }
        }
示例#16
0
        private void PingCompletedCallback(object sender, PingCompletedEventArgs e, Chart chart, String chartname)
        {
            try
            {
                foreach (Label lbl in panel1.Controls.OfType <Label>())
                {
                    if (lbl.Name == chartname)
                    {
                        lbl.Text = " (X)   " + chartname + " -> " + e.Reply.Address.ToString() + " : " + e.Reply.Status.ToString() + " @ " + e.Reply.RoundtripTime;
                    }
                }

                if (e.Reply.Status != IPStatus.Success)
                {
                    //tbresults.Text += Environment.NewLine + e.Reply.Address.ToString() + " : "+  e.Reply.Status.ToString();
                    chart.Series[0].Points.Add(80).Color = Color.Red;
                }
                else
                {
                    Color col = new Color();
                    col = Color.Green;

                    if (e.Reply.RoundtripTime < 20)
                    {
                        col = Color.Green;
                    }
                    else if (e.Reply.RoundtripTime >= 20 && e.Reply.RoundtripTime <= 35)
                    {
                        col = Color.Yellow;
                    }
                    else if (e.Reply.RoundtripTime > 35)
                    {
                        col = Color.BlueViolet;
                    }
                    chart.Series[0].Points.Add(e.Reply.RoundtripTime).Color = col;
                }
            }catch (NullReferenceException)
            {
                // in case the pinger was deleted while async task was running and this is the callback
                // Nothing
            }
        }
示例#17
0
        public static async Task SendAsyncs_ReuseInstance_Hostname()
        {
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();

            using (Ping p = new Ping())
            {
                TaskCompletionSource <bool> tcs = null;
                PingCompletedEventArgs      ea  = null;
                p.PingCompleted += (s, e) =>
                {
                    ea = e;
                    tcs.TrySetResult(true);
                };
                Action reset = () =>
                {
                    ea  = null;
                    tcs = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
                };

                // Several normal iterations
                for (int i = 0; i < 3; i++)
                {
                    reset();
                    p.SendAsync(TestSettings.LocalHost, null);
                    await tcs.Task;

                    Assert.NotNull(ea);
                    Assert.Equal(IPStatus.Success, ea.Reply.Status);
                    Assert.True(ea.Reply.Address.Equals(localIpAddress));
                }

                // Several canceled iterations
                for (int i = 0; i < 3; i++)
                {
                    reset();
                    p.SendAsync(TestSettings.LocalHost, null);
                    p.SendAsyncCancel(); // will block until operation can be started again
                }
                await tcs.Task;
                Assert.True(ea.Cancelled ^ (ea.Error != null) ^ (ea.Reply != null));
            }
        }
示例#18
0
        public void KoniecPing(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                listBox1.Items.Add("Błąd: Operacja ptrzerwana bądź nieprawisłowy adres ");
                ((IDisposable)(Ping)sender).Dispose();
                return;
            }
            PingReply odpowiedz = e.Reply;

            if (odpowiedz.Status == IPStatus.Success)
            {
                listBox1.Items.Add("Odpowiedź z " + odpowiedz.Address.ToString() + " bajtów=" + odpowiedz.Buffer.Length + " ms TTL=" + odpowiedz.Options.Ttl);
            }
            else
            {
                listBox1.Items.Add("Błąd: Brak odpowiedzi z " + e.Reply.Address + " : " + odpowiedz.Status);
            }
            ((IDisposable)(Ping)sender).Dispose();
        }
        private void OnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            ProcessNode(e.Reply.Address, e.Reply.Status);
            _options.Ttl += 1;

            if (!this.IsDone)
            {
                lock (lockerobj)
                {
                    if (_localPing == null)
                    {
                        ProcessNode(_destination, IPStatus.Unknown);
                    }
                    else
                    {
                        _localPing.SendAsync(_destination, _timeOut, Buffer, _options, null);
                    }
                }
            }
        }
示例#20
0
        private void PingRoundCompleted(object sender, PingCompletedEventArgs ev)
        {
            if (ev.Cancelled)
            {
                PingCompleted?.Invoke("Пинг отменён.", _configProtocol);
                ((AutoResetEvent)ev.UserState).Set();
            }

            if (ev.Error != null)
            {
                PingCompleted?.Invoke($"Ошибка пинга: {ev.Error}", _configProtocol);
                ((AutoResetEvent)ev.UserState).Set();
            }

            PingReply pingReply = ev.Reply;
            var       replyLog  = $"{DateTime.Now:dd MMMM yyyy HH:mm:ss} {_host} {pingReply.Status}";

            ((AutoResetEvent)ev.UserState).Set();
            PingCompleted?.Invoke(replyLog, _configProtocol);
        }
示例#21
0
        public void EndPing(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                this.messages.Add("Błąd : Operacja przerwana bądź nieprawidłowy adres");
                ((IDisposable)(Ping)sender).Dispose();
                return;
            }
            PingReply reply = e.Reply;

            if (reply.Status == IPStatus.Success)
            {
                this.messages.Add("Odpowiedz z " + reply.Address.ToString() + " bajtow " + reply.Buffer.Length + " czas " + reply.RoundtripTime + " TTL " + reply.Options.Ttl);
            }
            else
            {
                this.messages.Add("Błąd " + e.Reply.Address + " " + reply.Status);
            }
            ((IDisposable)(Ping)sender).Dispose();
        }
示例#22
0
        private static void PingCompletedCallback(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                Console.WriteLine("Ping canceled.");
            }

            if (e.Error != null)
            {
                Console.WriteLine("Ping failed:");
                Console.WriteLine(e.Error.ToString());
            }
            else
            {
                PingReply reply = e.Reply;
                DisplayReply(reply);
            }

            ((AutoResetEvent)e.UserState).Set();
        }
示例#23
0
        /// <summary>
        /// Ping结束事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ping_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            //触发Mesh设备列表进行更新
            string ip = (string)e.UserState;

            if (e.Reply.Status == IPStatus.Success)
            {
                logger.Info(string.Format("Ping\"{0}\":{1}", ip, e.Reply.Status.ToString()));
            }
            string status = e.Reply.Status == IPStatus.Success ? "在线" : "离线";

            if (ucGISVideo != null)
            {
                ucGISVideo.UpdateMeshStatus(ip, status);
            }
            if (ucAudioVideoProcess != null)
            {
                ucAudioVideoProcess.UpdateMeshStatus(ip, status);
            }
        }
示例#24
0
        private void OnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (!this.cancel)
            {
                this.ProcessHop(e.Reply.Address, e.Reply.Status);

                if (e.Reply.Status != IPStatus.TimedOut)
                {
                    this.pingOptions.Ttl++;
                }

                if (!this.Idle)
                {
                    lock (this)
                    {
                        this.ping.SendAsync(this.destinationIP, this.HopTimeOut, this.buffer, this.pingOptions, null);
                    }
                }
            }
        }
示例#25
0
        private void PingComplete(object sender, PingCompletedEventArgs e)
        {
            PingReply Reply;

            if (e.Cancelled)
            {
                Console.WriteLine("Ping Cencelled");
                ((AutoResetEvent)e.UserState).Set();
            }
            else if (e.Error != null)
            {
                Console.WriteLine("Fatal error!!!" + e.Error);
                ((AutoResetEvent)e.UserState).Set();
            }
            else
            {
                Reply = e.Reply;
                PingResult(Reply);
            }
        }
        private void p_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;

            Console.WriteLine("scanning {0}", ip);

            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                /*
                 * string name;
                 *  try
                 *  {
                 *      IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                 *      name = hostEntry.HostName;
                 *  }
                 *  catch (SocketException ex)
                 *  {
                 *      name = "?";
                 *  }
                 *  Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
                 */
                string name;
                try
                {
                    IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                    name = hostEntry.HostName;
                }
                catch (SocketException ex)
                {
                    name = "name unknown\nException: " + ex;
                }
                Console.WriteLine("found one --> {0}", ip);
                string nameForListbox = "" + ip + "\t(" + name + ")";
                lock (lockObj)
                {
                    upCount++;
                    foundIps.Add(nameForListbox);
                }
            }
            countdown.Signal();
        }
示例#27
0
        void ping_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                listBox1.Items.Add(e.Error.Message);
                return;
            }
            if (e.Cancelled)
            {
                listBox1.Items.Add("Przerwano operację na życzenie użytkownika.");
            }
            else
            {
                if (e.Reply.Status == IPStatus.TtlExpired)
                {
                    listBox1.Items.Add("Skok " + i.ToString() + " host: " + e.Reply.Address.ToString());
                }
                if (e.Reply.Status == IPStatus.TimedOut)
                {
                    listBox1.Items.Add("Skok " + i.ToString() + " host: * Upłynął limit czasu żądania.");
                }
                if (e.Reply.Status == IPStatus.Success)
                {
                    listBox1.Items.Add("Skok " + i.ToString() + " host: " + e.Reply.Address.ToString());
                    return;

                    button1.Enabled = true;
                }
                if (i++ < (int)numericUpDown1.Value)
                {
                    PingOptions opcjePing = new PingOptions(i, true);
                    ping.SendAsync(textBox1.Text, (int)numericUpDown2.Value, bufor,
                                   opcjePing, null);
                }
                else
                {
                    listBox1.Items.Add("Przekroczono maksymalną liczbę skoków (parametr TTL = " + numericUpDown1.Value.ToString());
                    button1.Enabled = true;
                }
            }
        }
示例#28
0
        //Notified update of node status
        private void Ping_Complete(object sender, PingCompletedEventArgs k)
        {
            PingReply    reply   = k.Reply;
            IMachineInfo machine = k.UserState as IMachineInfo;

            try
            {
                if (reply.Status == IPStatus.Success)
                {
                    machine.Alive = (NodeState.Online);
                }
                else
                {
                    machine.Alive = (NodeState.Offline);
                }
            }
            catch (NullReferenceException e)
            {
                machine.Alive = (NodeState.Unknown);
            }
        }
示例#29
0
    public static void PingCompletedCallback(object sender, PingCompletedEventArgs e)
    {
        // If the operation was canceled, display a message to the user.
        if (e.Cancelled)
        {
//			Debug.Log("Ping canceled.");

            // Let the main thread resume.
            // UserToken is the AutoResetEvent object that the main thread
            // is waiting for.
        }

        // If an error occurred, display the exception to the user.
        if (e.Error != null)
        {
//			Debug.Log("Ping failed:");
            Debug.Log(e.Error.ToString());
        }

        Debug.Log("Roundtrip Time: " + e.Reply.RoundtripTime);
    }
示例#30
0
        private void EndPingSending(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                listPingResults.Items.Add("Wystąpił błąd lub przerwano operację."); //error of cancel
                ((IDisposable)(Ping)sender).Dispose();
                return;
            }
            PingReply reply = e.Reply;      //get reply

            if (reply.Status == IPStatus.Success)
            {
                listPingResults.Items.Add(reply.Address.ToString() + " odpowiedź " + reply.Buffer.Length + " bajtów. Czas odpowiedzi: "
                                          + reply.RoundtripTime + " ms TTL: " + reply.Options.Ttl); //insert to listBox
            }
            else
            {
                listPingResults.Items.Add("Brak odpowiedzi od adresu " + e.Reply.Address + " status: " + reply.Status);
                ((IDisposable)(Ping)sender).Dispose();
            }
        }
示例#31
0
文件: PING.cs 项目: orf53975/Remote
        private static void Ping_completed(object s, PingCompletedEventArgs e)
        {
            lock (@lock)
            {
                instances -= 1;
            }

            if (e.Reply.Status == IPStatus.Success)
            {
                Console.WriteLine(string.Concat("Active IP: ", e.Reply.Address.ToString()));
                result += 1;
                lock (@lock)
                {
                    addresses.Add(e.Reply.Address);
                }
            }
            else
            {
                //Console.WriteLine(String.Concat("Non-active IP: ", e.Reply.Address.ToString()))
            }
        }
示例#32
0
        public void EndPing(object sender, PingCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                listBox1.Items.Add("Operation aborted or wrong address");
                ((IDisposable)(Ping)sender).Dispose();
                return;
            }
            PingReply answer = e.Reply;

            if (answer.Status == IPStatus.Success)
            {
                listBox1.Items.Add("Answer with: " + answer.Address.ToString() + " bajt=" + answer.Buffer.Length
                                   + " time=" + answer.RoundtripTime + "ms TTL=" + answer.Options.Ttl);
            }
            else
            {
                listBox1.Items.Add("Error: " + answer.Address.ToString() + " " + answer.Status.ToString());
            }
            ((IDisposable)(Ping)sender).Dispose();
        }