Example #1
0
 private void AddMachine(string host)
 {
     if (host != "" && TestMachine(host) && PingItems.Where(p => p.Host == host).Count() == 0)
     {
         var pi = new PingItem();
         pi.Host = host;
         DNSEntry(pi);
         PingItems.Add(pi);
         machineToolStripMenuItem.BackColor = SystemColors.Window;
         RefreshTree();
         machineToolStripMenuItem.Text = "";
     }
     else
     {
         machineToolStripMenuItem.BackColor = Color.LightSalmon;
         if (host != "" && PingItems.Where(p => p.Host == host).Count() == 0 &&
             MessageBox.Show(host + " does not respond,\ndo you want to add it anyways?", "eew...",
                             MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
         {
             var pi = new PingItem();
             pi.Host = host;
             DNSEntry(pi);
             PingItems.Add(pi);
             machineToolStripMenuItem.BackColor = SystemColors.Window;
             RefreshTree();
             machineToolStripMenuItem.Text = "";
         }
     }
 }
Example #2
0
        private void scanPorts(string host, int[] sel = null, int from = 88, int to = 80)
        {
            var dt = new DataTable();
            var h  = new PingItem();

            h.Host = host;
            PingHost(h);
            bool ok = !h.Failing;

            if (!ok)
            {
                if (MessageBox.Show("Host does not respond to ping!\nDo you want to continue?", "Warning!", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ok = true;
                }
            }
            if (ok)
            {
                PortItems.Clear();
                if (sel == null)
                {
                    for (int i = from; i <= to; i++)
                    {
                        PortItems.Add((new PortItem {
                            port = i, host = host
                        }));
                    }
                }
                else
                {
                    foreach (var i in sel)
                    {
                        PortItems.Add((new PortItem {
                            port = i, host = host
                        }));
                    }
                }

                dt.Columns.Add("Port");
                dt.Columns.Add("Open");
                foreach (var p in PortItems)
                {
                    var r = dt.Rows.Add();
                    if (InfoItems.Where(t => t.Port == p.port.ToString()).Count() > 0)
                    {
                        r["Port"] = string.Format("{0} ({1})", p.port.ToString(), InfoItems.Where(t => t.Port == p.port.ToString()).First().Name);
                    }
                    else
                    {
                        r["Port"] = p.port.ToString();
                    }
                    r["Open"] = "Testing...";
                }
                foreach (var p in PortItems)
                {
                    Task.Run(() => CheckPort(p));
                }
            }
            dgPorts.DataSource = dt;
        }
Example #3
0
 private void PingHost(PingItem pi)
 {
     using (Ping pinger = new Ping())
     {
         string data = "";
         while (data.Length < numPacket.Value)
         {
             data += "a";
         }
         byte[]      buffer  = Encoding.ASCII.GetBytes(data);
         int         timeout = (int)numTicker.Value - 500;
         PingLogItem pii     = new PingLogItem();
         pi.pingMemory    = (int)numPingMem.Value;
         pi.TotalAttemps += 1;
         pii.PacketSize   = buffer.Length;
         pii.TimeOut      = timeout;
         try
         {
             PingReply reply = ConvertAndPingHost(pi.Host, pinger, timeout, buffer);
             pii.Message = reply == null ? "N/A" : reply.Status.ToString();
             if (reply != null)
             {
                 if (reply.Address != null)
                 {
                     pii.ReplyAddress = reply.Address.ToString();
                 }
                 if (reply.Status != IPStatus.Success)
                 {
                     pi.TotalFails += 1;
                     pii.Failed     = true;
                     pii.RoundTrip  = -1;
                 }
                 else
                 {
                     pii.RoundTrip = reply.RoundtripTime;
                 }
             }
             else
             {
                 pi.TotalFails += 1;
                 pii.Failed     = true;
                 pii.RoundTrip  = -1;
             }
         }
         catch (PingException pex)
         {
             pii.Message    = pex.Message;
             pi.TotalFails += 1;
             pii.Failed     = true;
             pii.RoundTrip  = -1;
         }
         pi.AddLogItem(pii);
         LogOutput(pi);
     }
 }
Example #4
0
 public void RefreshData(PingItem pi)
 {
     this.pi          = pi;
     chkHost.Checked  = !pi.Paused;
     chkRoute.Checked = !pi.PauseTrace;
     pg.Pings         = new List <int>();
     foreach (PingLogItem pl in pi.PingLog)
     {
         pg.Pings.Add((int)pl.RoundTrip);
     }
     this.Refresh();
 }
Example #5
0
        private int DrawPingDetails(PaintEventArgs e, int y, int x, PingItem pi, int fontSize, Brush b)
        {
            int pgy1 = y;

            e.Graphics.DrawString(pi.Host, new Font("Arial", fontSize, FontStyle.Bold), b, new Point(x, y));
            y += fontSize + 4;
            string t = string.Format("LastRT: {0}", pi.LastRoundTrip);

            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("AvgRT: {0}", pi.AvgRoundTrip);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("CurrentLoss: {0}%", pi.CurrentLoss);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("Attempts: {0}", pi.TotalAttemps);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("Fails: {0}", pi.TotalFails);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("TotalLoss: {0}%", pi.TotalLoss);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("PingIP: {0}", pi.LastPingIP);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            string ip = "";

            foreach (var i in pi.DNSAddess)
            {
                ip = ip == "" ? i : ";" + i;
            }
            t = string.Format("DNSIP: {0}", ip);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            y += fontSize + 4;
            t  = string.Format("DNSHost: {0}", pi.DNSHostName);
            e.Graphics.DrawString(t, new Font("Arial", fontSize), b, new Point(x, y));
            int pgy2 = y + fontSize;

            pg.Location = new Point(200, pgy1);
            pg.Size     = new System.Drawing.Size(400, pgy2 - pgy1);
            y          += fontSize + 40;
            return(y);
        }
Example #6
0
 private void DNSEntry(PingItem pi)
 {
     try
     {
         var host = Dns.GetHostEntry(pi.Host);
         pi.DNSAddess = new List <string>();
         foreach (var a in host.AddressList)
         {
             pi.DNSAddess.Add(a.MapToIPv4().ToString());
         }
         pi.DNSHostName = host.HostName;
     }
     catch
     {
         pi.DNSAddess.Add("");
         pi.DNSHostName = "";
     }
 }
Example #7
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);
            }
        }
Example #8
0
        private void LogOutput(PingItem pi)
        {
            LogBuffer lb = new LogBuffer();
            //                           This failed if the input was null (Thomas)
            PingLogItem pii = pi.PingLog.Where(i => null != i).OrderByDescending(i => i.ID).First();

            if (pii.Failed)
            {
                string ip = "";
                foreach (var i in pi.DNSAddess)
                {
                    ip = ip == "" ? i : ";" + i;
                }
                lb.data = string.Format("\n{0} - {1} - {2} | Count: {3} | Fails: {4} | LastRT: {5} | AvgRT: {6} | PingIP: {7} | DnsIP: {8} | DNSHost: {9}",
                                        pii.TimeStamp, pi.Host, pii.Message, pi.TotalAttemps, pi.TotalFails, pii.RoundTrip, pi.AvgRoundTrip, pi.LastPingIP, ip, pi.DNSHostName);
                lb.name = pi.Host;
                Log.Add(lb);
            }
        }
Example #9
0
 public StatusPanel(PingItem pi)
 {
     this.pi                  = pi;
     this.DoubleBuffered      = true;
     this.Paint              += StatusPanel_Paint;
     chkHost.Location         = new Point(10000, 10000);
     chkRoute.Location        = new Point(10000, 10000);
     pg.Location              = new Point(10000, 10000);
     btnReTrace.Location      = new Point(10000, 10000);
     btnReTrace.Size          = new System.Drawing.Size(70, 21);
     chkHost.CheckedChanged  += chkHost_CheckedChanged;
     chkRoute.CheckedChanged += chkRoute_CheckedChanged;
     btnReTrace.Click        += btnReTrace_Click;
     chkHost.Text             = "Ping Host";
     chkRoute.Text            = "Ping Trace";
     btnReTrace.Text          = "Re-Trace";
     this.Controls.Add(chkHost);
     this.Controls.Add(chkRoute);
     this.Controls.Add(pg);
     this.Controls.Add(btnReTrace);
 }