// Constructor
 public RouteNodeFoundEventArgs(TraceRtNode node)
 {
     this.node = node;
 }
Exemple #2
0
        // This displays the specified job index
        private void DisplayJob(int displayindex)
        {
            routearrow.Visible = false;

            // Update buttons
            for (int i = 0; i < routebuttons.Length; i++)
            {
                if (i == displayindex)
                {
                    if (jobs[displayindex].targetreachable)
                    {
                        routebuttons[i].StartInfoFlash();
                    }
                    else
                    {
                        routebuttons[i].StartWarningFlash();
                    }
                }
                else
                {
                    routebuttons[i].StopInfoFlash();
                    routebuttons[i].StopWarningFlash();
                }
            }

            TraceJob j      = jobs[displayindex];
            int      offset = (j.nodes.Count <= 11) ? 0 : j.nodes.Count - addresslabels.Length;

            while ((offset > 0) && (j.nodes[offset + 10].HostAddress == null))
            {
                offset--;
            }

            if (j.nodes.Count == 0)
            {
                // Setup all labels
                for (int i = 0; i < addresslabels.Length; i++)
                {
                    hostlabels[i].Visible    = false;
                    addresslabels[i].Visible = false;
                    pinglabels[i].Visible    = false;
                    hostlabels[i].Text       = "";
                    addresslabels[i].Text    = "";
                    pinglabels[i].Text       = "";
                }
                hostlabels[1].Text    = "        Trace route not available.";
                addresslabels[1].Text = "";
                pinglabels[1].Text    = "";
            }
            else
            {
                // Setup all labels
                for (int i = 0; i < addresslabels.Length; i++)
                {
                    hostlabels[i].Visible    = false;
                    addresslabels[i].Visible = false;
                    pinglabels[i].Visible    = false;

                    int nindex = offset + i;
                    if (nindex < j.nodes.Count)
                    {
                        TraceRtNode n = j.nodes[nindex];

                        if (!string.IsNullOrEmpty(n.HostName))
                        {
                            hostlabels[i].Text = n.HostName;
                        }
                        else
                        {
                            hostlabels[i].Text = "(Unknown Routepoint)";
                        }

                        if (n.HostAddress != null)
                        {
                            addresslabels[i].Text      = n.HostAddress.ToString();
                            addresslabels[i].ColorText = ColorIndex.ControlColor4;

                            pinglabels[i].Text = n.RoundTripTime + " ms";
                            if (n.RoundTripTime > 500)
                            {
                                pinglabels[i].ColorText = ColorIndex.ControlColorNegative;
                            }
                            else
                            {
                                pinglabels[i].ColorText = ColorIndex.ControlColor3;
                            }
                        }
                        else
                        {
                            pinglabels[i].Text         = "N/A";
                            pinglabels[i].ColorText    = ColorIndex.ControlColorNegative;
                            addresslabels[i].Text      = "(Unreachable)";
                            addresslabels[i].ColorText = ColorIndex.ControlColorNegative;
                        }

                        addresslabels[i].SetupColors(General.Colors);
                        pinglabels[i].SetupColors(General.Colors);
                    }
                    else
                    {
                        hostlabels[i].Text    = "";
                        addresslabels[i].Text = "";
                        pinglabels[i].Text    = "";
                    }
                }
            }
        }
 // Constructor
 public RouteNodeFoundEventArgs(TraceRtNode node)
 {
     this.node = node;
 }
Exemple #4
0
        // This performs the trace
        private void TraceThread()
        {
            Random rnd = new Random();
            PingReply pingreply;
            IPHostEntry hostentry;
            bool routecomplete = false;
            Ping ping = new Ping();
            PingOptions pingoptions;
            IPAddress destip = null;

            try
            {
                // Resolve target address
                IPHostEntry destentry = Dns.GetHostEntry(destaddr);
                destip = destentry.AddressList[rnd.Next(destentry.AddressList.Length)];

                // Check if destination responds
                pingoptions = new PingOptions(maxhops, true);
                pingreply = ping.Send(destip, pingtimeout, pingdata, pingoptions);
                destresponse = (pingreply.Status == IPStatus.Success);
            }
            catch(Exception)
            {
                destresponse = false;
            }

            if(destip != null)
            {
                // Start tracing
                int routedepth = 1;
                do
                {
                    DateTime starttime = DateTime.Now;

                    // Send ping to destination
                    // The routedepth will limit the number of hops the ping will take
                    pingoptions = new PingOptions(routedepth, true);
                    pingreply = ping.Send(destip, pingtimeout, pingdata, pingoptions);

                    if(pingreply.Address != null)
                    {
                        if(pingreply.Status == IPStatus.Success)
                        {
                            // Destination reached
                            routecomplete = true;
                        }
                        else
                        {
                            // Now we need to ping the address returned to figure out the RTT
                            // Stupid how the Ping calss can't measure the time even when the TTL expired
                            pingoptions = new PingOptions(maxhops, true);
                            pingreply = ping.Send(pingreply.Address, pingtimeout, pingdata, pingoptions);
                        }

                        try
                        {
                            // Find the hostname for the address
                            hostentry = Dns.GetHostEntry(pingreply.Address);
                        }
                        catch(Exception)
                        {
                            hostentry = null;
                        }
                    }
                    else
                    {
                        hostentry = null;
                    }

                    // Store the node
                    TraceRtNode n = new TraceRtNode(pingreply, hostentry);
                    lock(this)
                    {
                        nodes.Add(n);
                    }

                    try
                    {
                        // Delay until next ping to prevent flooding the network
                        DateTime endtime = DateTime.Now;
                        TimeSpan deltatime = endtime - starttime;
                        if((int)deltatime.TotalMilliseconds < flooddelay)
                            Thread.Sleep(flooddelay - (int)deltatime.TotalMilliseconds);
                    }
                    catch(ThreadInterruptedException e)
                    {
                        return;
                    }

                    routedepth++;
                }
                while(!routecomplete && (routedepth <= maxhops));
            }

            // Done!
            this.destreached = routecomplete;
            this.tracethread = null;
            if(TraceComplete != null)
                TraceComplete(this, EventArgs.Empty);
        }
Exemple #5
0
        // This performs the trace
        private void TraceThread()
        {
            Random      rnd = new Random();
            PingReply   pingreply;
            IPHostEntry hostentry;
            bool        routecomplete = false;
            Ping        ping          = new Ping();
            PingOptions pingoptions;
            IPAddress   destip = null;

            try
            {
                // Resolve target address
                IPHostEntry destentry = Dns.GetHostEntry(destaddr);
                destip = destentry.AddressList[rnd.Next(destentry.AddressList.Length)];

                // Check if destination responds
                pingoptions  = new PingOptions(maxhops, true);
                pingreply    = ping.Send(destip, pingtimeout, pingdata, pingoptions);
                destresponse = (pingreply.Status == IPStatus.Success);
            }
            catch (Exception)
            {
                destresponse = false;
            }

            if (destip != null)
            {
                // Start tracing
                int routedepth = 1;
                do
                {
                    DateTime starttime = DateTime.Now;

                    // Send ping to destination
                    // The routedepth will limit the number of hops the ping will take
                    pingoptions = new PingOptions(routedepth, true);
                    pingreply   = ping.Send(destip, pingtimeout, pingdata, pingoptions);

                    if (pingreply.Address != null)
                    {
                        if (pingreply.Status == IPStatus.Success)
                        {
                            // Destination reached
                            routecomplete = true;
                        }
                        else
                        {
                            // Now we need to ping the address returned to figure out the RTT
                            // Stupid how the Ping calss can't measure the time even when the TTL expired
                            pingoptions = new PingOptions(maxhops, true);
                            pingreply   = ping.Send(pingreply.Address, pingtimeout, pingdata, pingoptions);
                        }

                        try
                        {
                            // Find the hostname for the address
                            hostentry = Dns.GetHostEntry(pingreply.Address);
                        }
                        catch (Exception)
                        {
                            hostentry = null;
                        }
                    }
                    else
                    {
                        hostentry = null;
                    }

                    // Store the node
                    TraceRtNode n = new TraceRtNode(pingreply, hostentry);
                    lock (this)
                    {
                        nodes.Add(n);
                    }

                    try
                    {
                        // Delay until next ping to prevent flooding the network
                        DateTime endtime   = DateTime.Now;
                        TimeSpan deltatime = endtime - starttime;
                        if ((int)deltatime.TotalMilliseconds < flooddelay)
                        {
                            Thread.Sleep(flooddelay - (int)deltatime.TotalMilliseconds);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        return;
                    }

                    routedepth++;
                }while(!routecomplete && (routedepth <= maxhops));
            }

            // Done!
            this.destreached = routecomplete;
            this.tracethread = null;
            if (TraceComplete != null)
            {
                TraceComplete(this, EventArgs.Empty);
            }
        }