Ejemplo n.º 1
0
        public void ScanbyIP()
        {
            systems.Clear();
            ClearArpTable();
            String[] localIPs = GetIP(Dns.GetHostName()).Split(',');
            String localIP = localIPs[0];
            bool cancelled = false;
            if (localIPs.Length > 1)
            {
                poshsecframework.Interface.frmScan frm = new poshsecframework.Interface.frmScan();
                frm.IPs = localIPs;
                frm.StartPosition = FormStartPosition.CenterScreen;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    localIP = frm.SelectedIP;
                }
                else
                {
                    cancelled = true;
                }
                frm.Dispose();
                frm = null;
            }
            if (localIP != "" && localIP != null && !cancelled)
            {
                String[] ipparts = localIP.Split('.');
                if (ipparts != null && ipparts.Length == 4)
                {
                    if (shstatus) { frm.SetProgress(0, 255); }                    
                    int ip = 1;
                    bool cancel = false;
                    do
                    {
                        String host = ipparts[0] + "." + ipparts[1] + "." + ipparts[2] + "." + ip.ToString();
                        if (shstatus) { frm.SetStatus("Scanning " + host + ", please wait...");}
                        if (shstatus) { frm.SetProgress(ip, 255);}

                        poshsecframework.Network.ScanIP scn = new poshsecframework.Network.ScanIP();
                        scn.IPAddress = host;
                        scn.Index = ip;
                        scn.ScanIPComplete += scn_ScanIPComplete;
                        System.Threading.Thread thd = new System.Threading.Thread(scn.Scan);
                        thds.Add(thd);
                        thd.Start();
                        ip++;
                        if (shstatus) { cancel = frm.CancelIPScan; }
                    } while (ip < 255 && !cancel);
                    if (shstatus) { frm.SetStatus(StringValue.WaitingForHostResp); }
                    do
                    {
                        System.Threading.Thread.Sleep(100);
                    } while (ThreadsActive());
                    systems.Sort();
                    BuildArpTable();

                    if (shstatus) { frm.HideProgress();}
                    if (shstatus) { frm.SetStatus(StringValue.Ready);}

                    OnScanComplete(new poshsecframework.Network.ScanEventArgs(systems));
                }
            }
            else
            {
                OnScanCancelled(new EventArgs());
            }
        }
Ejemplo n.º 2
0
        public void ScanbyIP()
        {
            systems.Clear();
            ClearArpTable();
            String[] localIPs  = GetIP(Dns.GetHostName()).Split(',');
            String   localIP   = localIPs[0];
            bool     cancelled = false;

            if (localIPs.Length > 1)
            {
                poshsecframework.Interface.frmScan frm = new poshsecframework.Interface.frmScan();
                frm.IPs           = localIPs;
                frm.StartPosition = FormStartPosition.CenterScreen;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    localIP = frm.SelectedIP;
                }
                else
                {
                    cancelled = true;
                }
                frm.Dispose();
                frm = null;
            }
            if (localIP != "" && localIP != null && !cancelled)
            {
                String[] ipparts = localIP.Split('.');
                if (ipparts != null && ipparts.Length == 4)
                {
                    if (shstatus)
                    {
                        frm.SetProgress(0, 255);
                    }
                    int  ip     = 1;
                    bool cancel = false;
                    do
                    {
                        String host = ipparts[0] + "." + ipparts[1] + "." + ipparts[2] + "." + ip.ToString();
                        if (shstatus)
                        {
                            frm.SetStatus("Scanning " + host + ", please wait...");
                        }
                        if (shstatus)
                        {
                            frm.SetProgress(ip, 255);
                        }

                        poshsecframework.Network.ScanIP scn = new poshsecframework.Network.ScanIP();
                        scn.IPAddress       = host;
                        scn.Index           = ip;
                        scn.ScanIPComplete += scn_ScanIPComplete;
                        System.Threading.Thread thd = new System.Threading.Thread(scn.Scan);
                        thds.Add(thd);
                        thd.Start();
                        ip++;
                        if (shstatus)
                        {
                            cancel = frm.CancelIPScan;
                        }
                    } while (ip < 255 && !cancel);
                    if (shstatus)
                    {
                        frm.SetStatus(StringValue.WaitingForHostResp);
                    }
                    do
                    {
                        System.Threading.Thread.Sleep(100);
                    } while (ThreadsActive());
                    systems.Sort();
                    BuildArpTable();

                    if (shstatus)
                    {
                        frm.HideProgress();
                    }
                    if (shstatus)
                    {
                        frm.SetStatus(StringValue.Ready);
                    }

                    OnScanComplete(new poshsecframework.Network.ScanEventArgs(systems));
                }
            }
            else
            {
                OnScanCancelled(new EventArgs());
            }
        }