public void OnetimeSetup()
        {
            var host = new ScanHost("10.20.30.40")
            {
                HostName = "server1.domain.com",
                Ssh      = true
            };

            _deserializer = new PortScanDeserializer(ProtocolType.SSH2);
            var connectionTreeModel = _deserializer.Deserialize(new[] { host });
            var root = connectionTreeModel.RootNodes.First();

            _importedConnectionInfo = root.Children.First();
        }
        private void PortScanner_HostScanned(ScanHost host, int scannedCount, int totalCount)
        {
            if (InvokeRequired)
            {
                Invoke(new PortScannerHostScannedDelegate(PortScanner_HostScanned), new object[] { host, scannedCount, totalCount });
                return;
            }

            Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Host scanned " + host.HostIp, true);

            olvHosts.AddObject(host);
            prgBar.Maximum = totalCount;
            prgBar.Value   = scannedCount;
        }
예제 #3
0
        private void PortScanner_HostScanned(ScanHost host, int scannedCount, int totalCount)
        {
            if (InvokeRequired)
            {
                Invoke(new PortScannerHostScannedDelegate(PortScanner_HostScanned), new object[] { host, scannedCount, totalCount });
                return;
            }

            Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg, "Host scanned " + host.HostIp, true);

            ListViewItem listViewItem = host.ToListViewItem(_import);

            if (listViewItem != null)
            {
                lvHosts.Items.Add(listViewItem);
                listViewItem.EnsureVisible();
            }

            prgBar.Maximum = totalCount;
            prgBar.Value   = scannedCount;
        }
예제 #4
0
                private void StartScanBG()
                {
                    try
                    {
                        int hCount = 0;

                        foreach (string Host in Hosts)
                        {
                            if (BeginHostScanEvent != null)
                            {
                                BeginHostScanEvent(Host);
                            }

                            ScanHost sHost = new ScanHost(Host);
                            hCount++;

                            bool HostAlive = false;

                            HostAlive = IsHostAlive(Host);

                            if (HostAlive == false)
                            {
                                sHost.ClosedPorts.AddRange(Ports);
                                sHost.SetAllProtocols(false);
                            }
                            else
                            {
                                foreach (int Port in Ports)
                                {
                                    bool err = false;

                                    try
                                    {
                                        System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient(Host,
                                                                                                                  Port);

                                        err = false;
                                        sHost.OpenPorts.Add(Port);
                                    }
                                    catch (Exception)
                                    {
                                        err = true;
                                        sHost.ClosedPorts.Add(Port);
                                    }

                                    if (Port == ScanHost.SSHPort)
                                    {
                                        sHost.SSH = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.TelnetPort)
                                    {
                                        sHost.Telnet = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.HTTPPort)
                                    {
                                        sHost.HTTP = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.HTTPSPort)
                                    {
                                        sHost.HTTPS = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.RloginPort)
                                    {
                                        sHost.Rlogin = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.SerialPort)
                                    {
                                        sHost.Serial = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.RDPPort)
                                    {
                                        sHost.RDP = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.VNCPort)
                                    {
                                        sHost.VNC = System.Convert.ToBoolean(!err);
                                    }
                                }
                            }

                            if (HostAlive == true)
                            {
                                try
                                {
                                    sHost.HostName = System.Net.Dns.GetHostEntry(sHost.HostIP).HostName;
                                }
                                catch (Exception)
                                {
                                }
                            }

                            _ScannedHosts.Add(sHost);
                            if (HostScannedEvent != null)
                            {
                                HostScannedEvent(sHost, hCount, Hosts.Count);
                            }
                        }

                        if (ScanCompleteEvent != null)
                        {
                            ScanCompleteEvent(_ScannedHosts);
                        }
                    }
                    catch (Exception ex)
                    {
                        Runtime.MessageCollector.AddMessage(Messages.MessageClass.WarningMsg,
                                                            (string)
                                                            ("StartScanBG failed (Tools.PortScan)" + Constants.vbNewLine +
                                                             ex.Message), true);
                    }
                }
예제 #5
0
        private void ImportScannedHost(ScanHost host, ContainerInfo parentContainer)
        {
            var finalProtocol = default(ProtocolType);
            var protocolValid = true;

            switch (_targetProtocolType)
            {
            case ProtocolType.SSH2:
                if (host.SSH)
                {
                    finalProtocol = ProtocolType.SSH2;
                }
                break;

            case ProtocolType.Telnet:
                if (host.Telnet)
                {
                    finalProtocol = ProtocolType.Telnet;
                }
                break;

            case ProtocolType.HTTP:
                if (host.HTTP)
                {
                    finalProtocol = ProtocolType.HTTP;
                }
                break;

            case ProtocolType.HTTPS:
                if (host.HTTPS)
                {
                    finalProtocol = ProtocolType.HTTPS;
                }
                break;

            case ProtocolType.Rlogin:
                if (host.Rlogin)
                {
                    finalProtocol = ProtocolType.Rlogin;
                }
                break;

            case ProtocolType.RDP:
                if (host.RDP)
                {
                    finalProtocol = ProtocolType.RDP;
                }
                break;

            case ProtocolType.VNC:
                if (host.VNC)
                {
                    finalProtocol = ProtocolType.VNC;
                }
                break;

            default:
                protocolValid = false;
                break;
            }

            if (!protocolValid)
            {
                return;
            }
            var newConnectionInfo = new ConnectionInfo
            {
                Name     = host.HostNameWithoutDomain,
                Hostname = host.HostName,
                Protocol = finalProtocol
            };

            newConnectionInfo.SetDefaultPort();

            parentContainer.AddChild(newConnectionInfo);
        }
예제 #6
0
                private void StartScanBG()
                {
                    try
                    {
                        int hCount = 0;

                        foreach (string Host in Hosts)
                        {
                            if (BeginHostScanEvent != null)
                                BeginHostScanEvent(Host);

                            ScanHost sHost = new ScanHost(Host);
                            hCount++;

                            bool HostAlive = false;

                            HostAlive = IsHostAlive(Host);

                            if (HostAlive == false)
                            {
                                sHost.ClosedPorts.AddRange(Ports);
                                sHost.SetAllProtocols(false);
                            }
                            else
                            {
                                foreach (int Port in Ports)
                                {
                                    bool err = false;

                                    try
                                    {
                                        System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient(Host,
                                                                                                                  Port);

                                        err = false;
                                        sHost.OpenPorts.Add(Port);
                                    }
                                    catch (Exception)
                                    {
                                        err = true;
                                        sHost.ClosedPorts.Add(Port);
                                    }

                                    if (Port == ScanHost.SSHPort)
                                    {
                                        sHost.SSH = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.TelnetPort)
                                    {
                                        sHost.Telnet = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.HTTPPort)
                                    {
                                        sHost.HTTP = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.HTTPSPort)
                                    {
                                        sHost.HTTPS = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.RloginPort)
                                    {
                                        sHost.Rlogin = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.SerialPort)
                                    {
                                        sHost.Serial = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.RDPPort)
                                    {
                                        sHost.RDP = System.Convert.ToBoolean(!err);
                                    }
                                    else if (Port == ScanHost.VNCPort)
                                    {
                                        sHost.VNC = System.Convert.ToBoolean(!err);
                                    }
                                }
                            }

                            if (HostAlive == true)
                            {
                                try
                                {
                                    sHost.HostName = System.Net.Dns.GetHostEntry(sHost.HostIP).HostName;
                                }
                                catch (Exception)
                                {
                                }
                            }

                            _ScannedHosts.Add(sHost);
                            if (HostScannedEvent != null)
                                HostScannedEvent(sHost, hCount, Hosts.Count);
                        }

                        if (ScanCompleteEvent != null)
                            ScanCompleteEvent(_ScannedHosts);
                    }
                    catch (Exception ex)
                    {
                        Runtime.MessageCollector.AddMessage(Messages.MessageClass.WarningMsg,
                                                            (string)
                                                            ("StartScanBG failed (Tools.PortScan)" + Constants.vbNewLine +
                                                             ex.Message), true);
                    }
                }