Пример #1
0
        private void updateTableRow(Hop curHop, ListViewItem curItem)
        {
            // if prev ip != cur ip
            if (curItem.SubItems[1].Text != curHop.ip.ToString())
            {
                curItem.SubItems[1].Text = curHop.ip.ToString();
            }

            // if prev time != cur time
            if (curItem.SubItems[2].Text != curHop.time.ToString())
                curItem.SubItems[2].Text = curHop.time.ToString();

            // color code pings
            Color bg = curItem.SubItems[2].BackColor;
            if (curHop.time <= MAX_PING_MS_GREEN && curHop.time != -1 && bg != Color.Lime) {
                curItem.SubItems[2].BackColor = Color.Lime;
            } else if (curHop.time > MAX_PING_MS_GREEN && curHop.time <= MAX_PING_MS_YELLOW && bg != Color.Yellow) {
                curItem.SubItems[2].BackColor = Color.Yellow;
            }
            else if (curHop.time > MAX_PING_MS_YELLOW || curHop.time == -1 && bg != Color.Red)
            {
                curItem.SubItems[2].BackColor = Color.Red;
            }
        }
Пример #2
0
 // only do this for the last hop
 private void updateCounters(Hop hop)
 {
     if (hop.time <= MAX_PING_MS_GREEN && hop.time >= 0)
     {
             this.counterGreen++;
     }
     else if (hop.time > MAX_PING_MS_GREEN && hop.time <= MAX_PING_MS_YELLOW)
     {
         this.counterYellow++;
     }
     else
     {
         this.counterRed++;
     }
 }
Пример #3
0
 private void updateLastTableRow(Hop curHop)
 {
     ListViewItem curItem = routeListView.Items[routeListView.Items.Count-1];
     updateTableRow(curHop, curItem);
     updateCounters(curHop);
 }
Пример #4
0
        private static bool doPing(int hopNum, List<Hop> hops, PingOptions pingOpts, Stopwatch watch,
            string ipAddrOrHostname,  int timeout , byte[] buffer)
        {
            pingOpts.Ttl = hopNum+1;

            // send ping and hop, and keep track of the time it takes
            Ping pinger = new Ping();
            watch.Reset();
            watch.Start();

            // make sure that the address is a valid one
            PingReply reply;
            try
            {
                reply = pinger.Send(ipAddrOrHostname, timeout, buffer, pingOpts);
            }
            catch (PingException e)
            {
                hops.Add(new Hop(hopNum, "Request timed out", -1, true));
                //break;
                return false;
            }
            watch.Stop();

            // catch and fix timed out hops
            Hop curHop;
            if (reply.Status != IPStatus.TimedOut)
                curHop = new Hop(hopNum, reply.Address.ToString(), watch.ElapsedMilliseconds, false);
            else
                curHop = new Hop(hopNum, "Request timed out", -1, true);

            hops.Add(curHop);

            // destination reached
            if (reply.Status == IPStatus.Success)
            {
                //break;
                return false;
            }
            return true;
        }