Example #1
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     try
     {
         if (ScanType.SelectedItem.ToString() == "Dns Entries")
         {
             sercher = new Thread(new ThreadStart(FindUsingDns));
             // add.Items.Clear();
             try
             {
                 IPAddress from = IPAddress.Parse(ipFrom.Text);
                 IPAddress to   = IPAddress.Parse(ipTo.Text);
             }
             catch (FormatException fe)
             {
                 MessageBox.Show(fe.Message);
                 return;
             }
             sercher.Name = "Network searching thread";
             sercher.Start();
             //add.Items.Add("    -->> >>> Please wait while processing is done <<< <<--");
             IPScan.AppendText("    -->> >>> Please wait while processing is done <<< <<--" + "\n");
             //Thread.Sleep(1);
         }
         else if (ScanType.SelectedItem.ToString() == "Ping Scan")
         {
             // MessageBox.Show("You Chose Ping Scan");
             sercher = new Thread(new ThreadStart(FindUsingPing));
             // add.Items.Clear();
             try
             {
                 IPAddress from = IPAddress.Parse(ipFrom.Text);
                 IPAddress to   = IPAddress.Parse(ipTo.Text);
             }
             catch (FormatException fe)
             {
                 MessageBox.Show(fe.Message);
                 return;
             }
             sercher.Name = "Network searching thread";
             sercher.Start();
             // add.Items.Add("    -->> >>> Please wait while processing is done <<< <<--");
             IPScan.AppendText("    -->> >>> Please wait while processing is done <<< <<--" + "\n");
             //Thread.Sleep(1);
         }
         // else { MessageBox.Show("Please Choose The Scan Type"); }
     }
     catch { MessageBox.Show("Please Choose The Scan Type"); }
 }
Example #2
0
        void FindUsingPing()
        {
            string host = null; int attempts = 1;

            //int timeout=0; //Time to wait for replies In Milliseconds
            //add.Items.Add("    -- >>> >> >>> Found station <<< << <<< -- ");
            //add.Items.Add("Host Name                   IP  Address");
            IPScan.AppendText("    -- >>> >> >>> Found station <<< << <<< -- " + "\n");
            IPScan.AppendText("Host Name                   IP  Address" + "\n");
            int    lastF  = ipFrom.Text.LastIndexOf(".");
            int    lastT  = ipTo.Text.LastIndexOf(".");
            string frm    = ipFrom.Text.Substring(lastF + 1);
            string tto    = ipTo.Text.Substring(lastT + 1);
            int    result = 0;

            // Store values from the NumericUpDown to variables
            StartIP = int.Parse(frm);
            EndIP   = int.Parse(tto);;
            // Reset the progress bar
            prgIPScanning.Value = 0;
            // Set the max value of the progress bar
            prgIPScanning.Maximum = EndIP - StartIP + 1;
            //MessageBox.Show("From"+frm+"To "+tto+" Maximum"+(EndIP-StartIP+1));
            // Let the user know the application is busy
            Cursor.Current = Cursors.WaitCursor;

            Ping ping = new Ping();

            PingReply pingReply;

            //-----------------------------------------------------------------------------------

            System.Diagnostics.Debug.WriteLine(frm + " " + tto);
            for (int i = int.Parse(frm); i <= int.Parse(tto); i++)
            {
                try
                {
                    string address = ipTo.Text.Substring(0, lastT + 1);
                    System.Diagnostics.Debug.WriteLine(ipTo.Text.Substring(0, lastT + 1) + i);
                    IPHostEntry he = Dns.GetHostByAddress(address + i);
                    // IPHostEntry Ipe = Dns.GetHostEntry();
                    ////add.Items.Add(he.HostName + "                  " + address + i);
                    host = address + i.ToString();

                    for (int j = 0; j < attempts; j++)
                    {
                        try
                        {
                            // pingReply = ping.Send(host, timeout);
                            pingReply = ping.Send(host);

                            // If there is a successful ping then return true.
                            if (pingReply != null &&
                                pingReply.Status == System.Net.NetworkInformation.IPStatus.Success)
                            {
                                //return true;
                                // add.Items.Add(he.HostName + "                  " + address + i);
                                IPScan.AppendText(he.HostName + "                      " + address + i + "\n");
                            }
                        }
                        catch
                        {
                            // Do nothing and let it try again until the attempts are exausted.
                            // Exceptions are thrown for normal ping failurs like address lookup
                            // failed.  For this reason we are supressing errors.
                        }
                    }

                    // Return false if we can't successfully ping the server after several attempts.
                    // return false;



                    //        add.Items.Add(he.HostName+"      "+address+i.ToString());
                    result += 1;
                }

                catch (SocketException)
                {
                    // in cazul unei erori
                }
                catch (Exception)
                {
                    // previne bloacarea programului
                }
                prgIPScanning.PerformStep();
            }
            MessageBox.Show("IP Scanning Done..!");
            // Set the cursor back to normal

            Cursor.Current = Cursors.Arrow;
            //-----------------------------------------------------------------------------------------------------------
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        void FindUsingDns() //
        {
            // add.Items.Add("    -- >>> >> >>> Found station <<< << <<< -- ");
            // add.Items.Add("Host Name                   IP  Address");
            IPScan.AppendText("    -- >>> >> >>> Found station <<< << <<< -- " + "\n");
            IPScan.AppendText("Host Name                   IP  Address" + "\n");
            int    lastF  = ipFrom.Text.LastIndexOf(".");
            int    lastT  = ipTo.Text.LastIndexOf(".");
            string frm    = ipFrom.Text.Substring(lastF + 1);
            string tto    = ipTo.Text.Substring(lastT + 1);
            int    result = 0;

            // Store values from the NumericUpDown to variables
            StartIP = int.Parse(frm);
            EndIP   = int.Parse(tto);
            // Reset the progress bar
            prgIPScanning.Value = 0;
            // Set the max value of the progress bar
            prgIPScanning.Maximum = EndIP - StartIP + 1;
            MessageBox.Show("From" + frm + "To " + tto + " Maximum" + (EndIP - StartIP + 1));
            // Let the user know the application is busy
            Cursor.Current = Cursors.WaitCursor;

            System.Diagnostics.Debug.WriteLine(frm + " " + tto);
            for (int i = int.Parse(frm); i <= int.Parse(tto); i++)
            {
                try
                {
                    string address = ipTo.Text.Substring(0, lastT + 1);
                    System.Diagnostics.Debug.WriteLine(ipTo.Text.Substring(0, lastT + 1) + i);
                    IPHostEntry he = Dns.GetHostByAddress(address + i);
                    // IPHostEntry Ipe = Dns.GetHostEntry();
                    //  add.Items.Add(he.HostName+"                  "+address+i);
                    IPScan.AppendText(he.HostName + "                  " + address + i + "\n");

                    //foreach (DataGridView row in ScanGrid.Rows)
                    //{

                    //    // ScanGrid.UpdateCellValue(0,0) = address + i;



                    //}


                    //        add.Items.Add(he.HostName+"      "+address+i.ToString());
                    result += 1;
                }

                catch (SocketException)
                {
                    // in cazul unei erori
                }
                catch (Exception)
                {
                    // previne bloacarea programului
                }

                prgIPScanning.PerformStep();
            }
            // Set the cursor back to normal

            Cursor.Current = Cursors.Arrow;
        }