コード例 #1
0
ファイル: Form1.cs プロジェクト: Hagser/csharp
        private void lookupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedCells.Count == 1)
            {
                DataGridViewCell dc = dataGridView1.SelectedCells[0];
                DataGridViewColumn dgc = dataGridView1.Columns[dc.ColumnIndex];
                if (dgc.Name.Equals("src-ip") || dgc.Name.Equals("dst-ip"))
                {
                    string Ip = dc.Value.ToString();
                    if (!Ip.StartsWith("192.168") && !Ip.StartsWith("255.") && !Ip.Equals("239.255.255.250"))
                    {
                        
                            System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
                            ping.PingCompleted += (a, b) =>
                            {
                                MessageBox.Show(Ip + "\n" + b.Reply.Status.ToString());
                            };
                            IPAddress address;
                            if (IPAddress.TryParse(Ip, out address))
                            {
                                if (!iptrace.ContainsKey(address))
                                {
                                    if (!iphost.ContainsKey(address))
                                    {
                                        try
                                        {
                                            IPHostEntry iph = System.Net.Dns.EndGetHostEntry(System.Net.Dns.BeginGetHostEntry(address, (a) =>
                                            {
                                                if (a.IsCompleted)
                                                {
                                                    string s = "";
                                                }
                                            }, null));
                                            iphost.Add(address, iph);
                                            AddToolTipTextToIp(address, iph);
                                        }
                                        catch { }
                                    }
                                    else
                                    {
                                        AddToolTipTextToIp(address, iphost[address]);
                                    }
                                    BackgroundWorker bw = new BackgroundWorker();
                                    bw.DoWork += (a, b) =>
                                        {
                                            IPAddress ipaddress = (IPAddress)b.Argument;
                                            TraceForm tf = new TraceForm(ipaddress);
                                            tf.Tag = Diag.PerformPathping(ipaddress, 50, 5000);
                                            iptrace.Add(address,tf);
                                            tf.ShowDialog();
                                        };
                                    bw.RunWorkerAsync(address);
                                }
                                else
                                {
                                    iptrace[address].ShowDialog();
                                }
                            }
                            //ping.SendAsync(dc.Value.ToString(),null);

                        
                    }
                }
                
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: bangush/csharp
 private void lookupToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedCells.Count == 1)
     {
         DataGridViewCell   dc  = dataGridView1.SelectedCells[0];
         DataGridViewColumn dgc = dataGridView1.Columns[dc.ColumnIndex];
         if (dgc.Name.Equals("src-ip") || dgc.Name.Equals("dst-ip"))
         {
             string Ip = dc.Value.ToString();
             if (!Ip.StartsWith("192.168") && !Ip.StartsWith("255.") && !Ip.Equals("239.255.255.250"))
             {
                 System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
                 ping.PingCompleted += (a, b) =>
                 {
                     MessageBox.Show(Ip + "\n" + b.Reply.Status.ToString());
                 };
                 IPAddress address;
                 if (IPAddress.TryParse(Ip, out address))
                 {
                     if (!iptrace.ContainsKey(address))
                     {
                         if (!iphost.ContainsKey(address))
                         {
                             try
                             {
                                 IPHostEntry iph = System.Net.Dns.EndGetHostEntry(System.Net.Dns.BeginGetHostEntry(address, (a) =>
                                 {
                                     if (a.IsCompleted)
                                     {
                                         string s = "";
                                     }
                                 }, null));
                                 iphost.Add(address, iph);
                                 AddToolTipTextToIp(address, iph);
                             }
                             catch { }
                         }
                         else
                         {
                             AddToolTipTextToIp(address, iphost[address]);
                         }
                         BackgroundWorker bw = new BackgroundWorker();
                         bw.DoWork += (a, b) =>
                         {
                             IPAddress ipaddress = (IPAddress)b.Argument;
                             TraceForm tf        = new TraceForm(ipaddress);
                             tf.Tag = Diag.PerformPathping(ipaddress, 50, 5000);
                             iptrace.Add(address, tf);
                             tf.ShowDialog();
                         };
                         bw.RunWorkerAsync(address);
                     }
                     else
                     {
                         iptrace[address].ShowDialog();
                     }
                 }
                 //ping.SendAsync(dc.Value.ToString(),null);
             }
         }
     }
 }