예제 #1
0
 private void PingTrace(TraceItem ti)
 {
     using (Ping pinger = new Ping())
     {
         ti.pingMemory = (int)numPingMem.Value;
         string data = "";
         while (data.Length < numPacket.Value)
         {
             data += "a";
         }
         byte[] buffer  = Encoding.ASCII.GetBytes(data);
         int    timeout = (int)numTicker.Value - 500;
         try
         {
             ti.TotalAttemps += 1;
             PingReply reply = ConvertAndPingHost(ti.Address, pinger, timeout, buffer);
             int       rt    = -1;
             if (reply != null && reply.Status == IPStatus.Success)
             {
                 rt = (int)reply.RoundtripTime;
             }
             ti.AddLogItem(rt);
             ti.TotalFails += rt == -1 ? 1 : 0;
         }
         catch
         {
         }
     }
 }
예제 #2
0
        private void TraceRoute(PingItem pi)
        {
            var  tr     = new TraceRoute((int)numTicker.Value - 500).GetTraceRoute(pi.Host);
            int  i      = 0;
            Ping pinger = new Ping();

            foreach (var t in tr)
            {
                TraceItem ti = new TraceItem();
                ti.Index   = i += 1;
                ti.Address = t;
                if (!t.Contains('*'))
                {
                    try
                    {
                        var host = Dns.GetHostEntry(ti.Address);
                        foreach (var a in host.AddressList)
                        {
                            ti.DNSAddess.Add(a.MapToIPv4().ToString());
                        }
                        ti.DNSHost = host.HostName;
                    }
                    catch { }
                    try
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            ti.TotalAttemps += 1;
                            PingReply p  = pinger.Send(t);
                            int       rt = -1;
                            if (p.Status == IPStatus.Success)
                            {
                                rt = (int)p.RoundtripTime;
                            }
                            ti.AddLogItem(rt);
                            ti.TotalFails += rt == -1 ? 1 : 0;
                        }
                    }
                    catch { }
                }
                pi.TraceRoute.Add(ti);
            }
        }