public void PingerLauncher(object pingparam)
        {
            StatusUpdater statusUpdater = StdUpd;

            DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Ping worker launcher started.");
            lock (totalaccesslock)
            {
                statisticpackcount = default_timewindow / pingparamdata.interval;
                sentpackcount      = 0;
            }
            lock (statisticaccesslock)
            {
                successpackcount = 0;
                failedpackcount  = 0;
                totalrtt         = 0;
                RTT.Clear();
            }
            Timer timer = new Timer(Pinger, pingparam, 0, pingparamdata.interval);

            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Ping worker lighter started.");
            controlon.WaitOne();
            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker launcher dying.");
            timer.Dispose(controlon);
            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker lighter broken.");
        }
Exemplo n.º 2
0
        public void PingerLauncher(object pingparam)
        {
            StatusUpdater statusUpdater = StdUpd;

            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Ping worker launcher started.");
            DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
            bool pingallowed;

            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Fetching Address...");
            DataSct.PingParam receivehostentry = FetchHostAddress(pingparamdata.destination);
            pingparamdata.resolvedhostname   = receivehostentry.resolvedhostname;
            pingparamdata.destinationaddress = receivehostentry.destinationaddress;
            if (pingparamdata.destinationaddress != null)
            {
                pingallowed = true;
            }
            else
            {
                pingallowed = false;
            }
            if (pingallowed)
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Destination check OK.");
                controlon.Reset();
                lock (totalaccesslock)
                {
                    statisticpackcount = default_timewindow / pingparamdata.interval;
                    sentpackcount      = 0;
                }
                lock (statisticaccesslock)
                {
                    successpackcount = 0;
                    failedpackcount  = 0;
                    totalrtt         = 0;
                    RTT.Clear();
                }
                Timer timer = new Timer(Pinger, pingparamdata, 0, pingparamdata.interval);
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Ping worker lighter started.");
                controlon.WaitOne();
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker launcher dying.");
                timer.Dispose(controlon);
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker lighter broken.");
            }
            else
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Network error or wrong destination, ping worker launcher dying.");
            }
        }
Exemplo n.º 3
0
        private void Start_Button_Click(object sender, RoutedEventArgs e)
        {
            string        dest          = "";
            Int32         bufferlength  = default_buffer;
            Int32         ttlvalue      = default_ttl;
            Int32         timeout       = default_timeout;
            Int32         interval      = default_interval;
            byte          checker       = 0x00; //A bitfield checker
            FieldUpdater  fieldUpdater  = FldUpd;
            StatusUpdater statusUpdater = StdUpd;

            Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Statring validation...");
            //Valid IP or domain name
            if (Destination_Fill.Text != "")
            {
                dest    = Destination_Fill.Text;
                checker = (byte)(checker | (byte)0x01);
            }
            else
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "No destination filled.");
            }
            //Valid buffer size
            if (Buffer_Size.Text != "")
            {
                if (CheckANumber(Buffer_Size.Text))
                {
                    if ((bufferlength = CheckNumberBetween(Convert.ToInt32(Buffer_Size.Text), 32, 65500)) != -1)
                    {
                        checker = (byte)(checker | (byte)0x02);
                    }
                    else
                    {
                        Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid buffer size setting.");
                    }
                }
                else
                {
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid buffer size Input.");
                }
            }
            else
            {
                Dispatcher.Invoke(fieldUpdater, ValueSign.FieldSign.BufferSize, bufferlength.ToString());
                checker = (byte)(checker | (byte)0x02);
            }
            //Valid TTL
            if (TTL_Count.Text != "")
            {
                if (CheckANumber(TTL_Count.Text))
                {
                    if ((ttlvalue = CheckNumberBetween(Convert.ToInt32(TTL_Count.Text), 1, 255)) != -1)
                    {
                        checker = (byte)(checker | (byte)0x04);
                    }
                    else
                    {
                        Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid TTL Value.");
                    }
                }
                else
                {
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid TTL Input.");
                }
            }
            else
            {
                Dispatcher.Invoke(fieldUpdater, ValueSign.FieldSign.TTL, ttlvalue.ToString());
                checker = (byte)(checker | (byte)0x04);
            }
            //Valid Timeout
            if (Timeout_Count.Text != "")
            {
                if (CheckANumber(Timeout_Count.Text))
                {
                    if ((timeout = CheckNumberLarger(Convert.ToInt32(Timeout_Count.Text), 1)) != -1)
                    {
                        checker = (byte)(checker | (byte)0x08);
                    }
                    else
                    {
                    }
                }
                else
                {
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid timeout input.");
                }
            }
            else
            {
                Dispatcher.Invoke(fieldUpdater, ValueSign.FieldSign.TimeOut, timeout.ToString());
                checker = (byte)(checker | (byte)0x08);
            }
            //Valid interval
            if (Interval_Count.Text != "")
            {
                if (CheckANumber(Interval_Count.Text))
                {
                    if ((interval = CheckNumberLarger(Convert.ToInt32(Interval_Count.Text), 1)) != -1)
                    {
                        checker = (byte)(checker | (byte)0x10);
                    }
                    else
                    {
                    }
                }
                else
                {
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Invalid interval input.");
                }
            }
            else
            {
                Dispatcher.Invoke(fieldUpdater, ValueSign.FieldSign.Interval, interval.ToString());
                checker = (byte)(checker | (byte)0x10);
            }
            //Check Valid
            if (checker == 0x1F)
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Validation completed, preparing...");
                DataSct.PingParam pingparamdata = new DataSct.PingParam
                {
                    destination = dest,
                    buffersize  = bufferlength,
                    dflag       = Is_DF.IsChecked.Value,
                    ttl         = ttlvalue,
                    timeout     = timeout,
                    interval    = interval
                };
                UIElementEnabler(false);
                pingworker = new Thread(new ParameterizedThreadStart(PingerLauncher))
                {
                    IsBackground = true,
                    Name         = "Ping Worker",
                    Priority     = ThreadPriority.AboveNormal
                };
                pingworker.Start((object)pingparamdata);
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Ping worker launcher has been called.");
            }
            else
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Validation failed for wrong parameters.");
            }
        }
Exemplo n.º 4
0
        public void Pinger(object pingparam)
        {
            DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
            Ping          pingwork = new Ping();
            StatusUpdater statusUpdater = StdUpd;
            string        destinationdisplay, destinationresolvedname;

            if (pingparamdata.resolvedhostname != null)
            {
                destinationresolvedname = pingparamdata.resolvedhostname;
            }
            else
            {
                destinationresolvedname = pingparamdata.destination;
            }
            if (string.Compare(destinationresolvedname, pingparamdata.destinationaddress.ToString(), true) != 0)
            {
                destinationdisplay = destinationresolvedname + " (" + pingparamdata.destinationaddress.ToString() + ")";
            }
            else
            {
                destinationdisplay = pingparamdata.destinationaddress.ToString();
            }
            try
            {
                PingReply pingReply = pingwork.Send(pingparamdata.destinationaddress, pingparamdata.timeout, new byte[pingparamdata.buffersize], new PingOptions(pingparamdata.ttl, pingparamdata.dflag));
                lock (totalaccesslock)
                {
                    if (sentpackcount < statisticpackcount)
                    {
                        sentpackcount += 1;
                    }
                }
                if (pingReply.Status == IPStatus.Success)
                {
                    PackCouter(true, pingReply.RoundtripTime);
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.CurrentPing, pingReply.RoundtripTime.ToString("0ms"));
                    if (((pingReply.RoundtripTime > pingparamdata.interval) && (pingparamdata.interval >= 500)) || (pingReply.RoundtripTime >= 1000))
                    {
                        Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, destinationdisplay + " ICMP reply latecy too long: " + pingReply.RoundtripTime.ToString("0ms"));
                    }
                }
                else
                {
                    PackCouter(false, null);
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, destinationdisplay + " " + ICMPErrorAnalasys(pingReply.Status));
                    Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.CurrentPing, "Failed");
                }
            }
            catch (Exception exception)
            {
                ExceptionLogcat(exception);
            }
            double averagepingtime, packetlossrate;

            lock (statisticaccesslock)
            {
                averagepingtime = (double)totalrtt / (double)successpackcount;
                lock (totalaccesslock)
                {
                    packetlossrate = (double)failedpackcount / (double)sentpackcount;
                }
            }
            if (averagepingtime >= 0)
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.SmoothPing, averagepingtime.ToString("0.00ms"));
            }
            else
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.SmoothPing, "-");
            }
            if (packetlossrate >= 0)
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.PackageLoss, packetlossrate.ToString("0.00%"));
            }
            else
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.PackageLoss, "-");
            }
            if (!pingworker.IsAlive)
            {
                Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Ping worker launcher died.");
            }
        }