Exemple #1
0
    protected void addbutton_Click(object sender, EventArgs e)
    {
        host   temphost        = new host(hostipform.Text, hostnameform.Text, System.Int32.Parse(hostscanint.Text), grouptextbox.Text);
        string strAccessSelect = "SELECT Код FROM hosts";
        int    lastnum         = 0;

        OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbaddress);
        OleDbCommand    cmd        = new OleDbCommand(strAccessSelect, connection);

        cmd.CommandText = strAccessSelect;
        cmd.Connection  = connection;

        connection.Open();

        OleDbDataReader readID = cmd.ExecuteReader(); // Выполняем команду

        while (readID.Read())
        {
            lastnum = Convert.ToInt32(readID["Код"]); // Присваиваем таймеру значение максимального id
        }
        readID.Close();
        lastnum++;
        string strAccessInsert = "INSERT INTO hosts (код,ip,name,mac,scanint,grp) values (" + lastnum + ",'" + temphost.Ip + "','" + temphost.Name + "','" + temphost.Mac + "','" + temphost.Scanint + "','" + temphost.Group + "')";

        cmd.CommandText = strAccessInsert;
        cmd.ExecuteNonQuery();

        connection.Close();
    }
Exemple #2
0
    protected void resolvebutton_Click(object sender, EventArgs e)
    {
        host temphost = new host(hostipform.Text, hostnameform.Text, grouptextbox.Text);
        icmp tempicmp = new icmp();

        if (temphost.Ip == "")
        {
            hostipform.Text = tempicmp.resolveip(temphost.Name);
        }
        else
        {
            hostipform.Text = temphost.Ip;
        };

        if (temphost.Name == "")
        {
            hostnameform.Text = tempicmp.resolvename(temphost.Ip);
        }
        else
        {
            hostnameform.Text = temphost.Name;
        };

        resulttextbox.Text = tempicmp.ping(hostipform.Text);
    }
        public async Task <string> AddDnsHostRecordIPAddress(string reference, string ipAddress, bool enableDhcp = false, bool setHostName = false, string mac = "")
        {
            if (!String.IsNullOrEmpty(reference))
            {
                if (!String.IsNullOrEmpty(ipAddress))
                {
                    IPAddress IP = IPAddress.Parse(ipAddress);

                    string HostName = String.Empty;

                    if (setHostName)
                    {
                        host Host = await base.GetIbxObject <host>(reference, new string[] { "ALL" });

                        HostName = Host.name;
                    }

                    string Data = "{\"ipv4addrs+\":[{\"ipv4addr\":\"" + IP.ToString() + "\"" +
                                  ",\"configure_for_dhcp\":" + ((enableDhcp) ? "true" : "false") +
                                  ((!String.IsNullOrEmpty(mac)) ? ",\"mac\":\"" + mac + "\"" : "") +
                                  ((setHostName) ? ",\"options\":[{\"name\":\"host-name\",\"num\":12,\"value\":\"" + HostName + "\"}]" : "") +
                                  "}]}";

                    return(await base.UpdateIbxObject <host>(reference, Data));
                }
                else
                {
                    throw new ArgumentNullException("ipAddress", "The IP address to add cannot be null or empty.");
                }
            }
            else
            {
                throw new ArgumentNullException("reference", "Reference data cannot be null or empty.");
            }
        }
Exemple #4
0
    protected void testbutton_Click(object sender, EventArgs e)
    {
        host temphost = new host(hostipform.Text);
        icmp tempicmp = new icmp();

        resulttextbox.Text = tempicmp.ping(temphost.Ip);
    }
Exemple #5
0
    protected void addbutton_Click(object sender, EventArgs e)
    {
        host temphost = new host(hostipform.Text, hostnameform.Text, System.Int32.Parse(hostscanint.Text), grouptextbox.Text);
        string strAccessSelect = "SELECT Код FROM hosts";
        int lastnum = 0;

        OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbaddress);
        OleDbCommand cmd = new OleDbCommand(strAccessSelect, connection);
        cmd.CommandText = strAccessSelect;
        cmd.Connection = connection;

        connection.Open();

        OleDbDataReader readID = cmd.ExecuteReader(); // Выполняем команду
        while (readID.Read())
        {
            lastnum = Convert.ToInt32(readID["Код"]); // Присваиваем таймеру значение максимального id
        }
        readID.Close();
        lastnum++;
        string strAccessInsert = "INSERT INTO hosts (код,ip,name,mac,scanint,grp) values (" + lastnum + ",'" + temphost.Ip + "','" + temphost.Name + "','" + temphost.Mac + "','" + temphost.Scanint + "','" + temphost.Group + "')";
        cmd.CommandText = strAccessInsert;
        cmd.ExecuteNonQuery();

        connection.Close();
    }
Exemple #6
0
        private static void ScanHostConfig()
        {
            LibWinInventory _obj         = new LibWinInventory();
            host            DetectedHost = _obj.RunDetection();

            JsonHostConfig     = _obj.ExportToJsonString(DetectedHost);
            JsonHostConfigSize = JsonHostConfig.Length.ToString();
        }
Exemple #7
0
 /// <summary>
 /// HTTP服务
 /// </summary>
 /// <param name="servers">HTTP服务器</param>
 /// <param name="host">TCP服务端口信息</param>
 public sslServer(servers servers, ref host host)
     : base(servers, ref host)
 {
     certificate = fastCSharp.config.http.Default.GetCertificate(ref host, ref protocol);
     if (certificate == null)
     {
         fastCSharp.log.Error.Add("安全证书获取失败 " + host.Host + ":" + host.Port.toString(), null, false);
     }
     else if (protocol == SslProtocols.None)
     {
         protocol = SslProtocols.Tls;
     }
 }
Exemple #8
0
        private string ExtractVendor(host item)
        {
            if (item.Items == null || item.Items.Length < 1)
            {
                return(String.Empty);
            }
            foreach (var o in item.Items)
            {
                var typeOfO = o.GetType();
                if (typeOfO.Equals(typeof(address)))
                {
                    return(((address)o).vendor);
                }
            }

            return(String.Empty);
        }
Exemple #9
0
        public static void updateDatabaseEntry(host host) //sends a single host not a list.
        {
            using (var connectionC = connection())        //uses one subroutine for the connection string builder
            {
                connectionC.Open();

                //todo: 11/1/20 add some exception handling
                using (var transaction = connectionC.BeginTransaction())
                {
                    var insertCmd = connectionC.CreateCommand();
                    insertCmd.CommandText = $"UPDATE hosts SET purpose = '{host.purpose}', Manufacturer = '{host.manufacturer}', " +
                                            $"serial = '{host.serial}', warranty = '{host.warranty}', Model = '{host.model}', MAC = '{host.MAC}', OS = '{host.OS}'  " +
                                            $"WHERE name = '{host.hostname}';";
                    insertCmd.ExecuteNonQuery();
                    transaction.Commit();
                }
            }
        }
Exemple #10
0
    protected void resolvebutton_Click(object sender, EventArgs e)
    {
        host temphost = new host(hostipform.Text, hostnameform.Text, grouptextbox.Text);
        icmp tempicmp = new icmp();

        if (temphost.Ip == "")
        {
            hostipform.Text = tempicmp.resolveip(temphost.Name);
        }
        else { hostipform.Text = temphost.Ip; };

        if (temphost.Name == "")
        {
            hostnameform.Text = tempicmp.resolvename(temphost.Ip);
        }
        else { hostnameform.Text = temphost.Name; };

        resulttextbox.Text = tempicmp.ping(hostipform.Text);
    }
Exemple #11
0
        /// <summary>
        /// HTTP服务
        /// </summary>
        /// <param name="servers">HTTP服务器</param>
        /// <param name="host">TCP服务端口信息</param>
        public server(servers servers, ref host host)
            : base(new code.cSharp.tcpServer {
            Host = host.Host, Port = host.Port, AcceptThreadCount = fastCSharp.config.http.Default.AcceptThreadCount, IsServer = true
        })
        {
            this.Servers = servers;
            DomainCount  = 1;

            int maxActiveSocketCount = servers.Attribute.MaxActiveClientCountIpAddress;

            if (maxActiveSocketCount > 0)
            {
                int maxSocketCount = Math.Max(servers.Attribute.MaxClientCountPerIpAddress, maxActiveSocketCount);
                socketQueues = new socketQueue[256];
                for (int index = 256; index != 0; socketQueues[--index].Set(this, maxActiveSocketCount, maxSocketCount))
                {
                    ;
                }
            }
        }
Exemple #12
0
        public static List <host> verifyCSV(string hostFromCSV)
        {
            //todo: make methods to ensure data from CSV is valid. 05/12/20
            //make it take a string array and convert each line into a host in a hostlist

            String[] extractedStrings = hostFromCSV.Split(',');
            ///todo: count how  many values per line by number of commas
            ///


            if (extractedStrings.Length > 11)
            {
                //to test: 06/12/20
                MessageBox.Show("extracted string lentgh is invalid" + extractedStrings.Length);
                return(null);
            }

            //importedHost.hostname = extractedStrings[0];
            host        importedHost    = new host();
            List <host> importListhosts = new List <host>();

            importListhosts.Add(new host()
            {
                hostname     = extractedStrings[0],
                purpose      = extractedStrings[1],
                OS           = extractedStrings[2],
                MAC          = extractedStrings[3],
                serial       = extractedStrings[4],
                warranty     = extractedStrings[5],
                manufacturer = extractedStrings[6],
                model        = extractedStrings[7],
                location     = extractedStrings[8],
                owner        = extractedStrings[9],
                notes        = extractedStrings[10]
            });;

            MessageBox.Show("extrateced hostname: " + extractedStrings[0] + "\t" + extractedStrings[1] + "\t" + extractedStrings[2] + "\t" + extractedStrings[3] + "\t" + extractedStrings[4] + "\t" + extractedStrings[5] + "\t" + extractedStrings[6] + "\t" + extractedStrings[7] + "\t" + extractedStrings[8] + "\t" + extractedStrings[9]
                            + "\t" + extractedStrings[10]);
            return(importListhosts);
        }
        public async Task <string> SetDnsHostRecordNextAvailableIP(string reference, string network, bool enableDhcp = false, bool setHostName = false, string mac = "")
        {
            if (!String.IsNullOrEmpty(reference))
            {
                string MACAddress  = String.Empty;
                string TempNetwork = String.Empty;

                if (NetworkAddressTest.IsMAC(mac, out MACAddress, true, true) && NetworkAddressTest.IsIPv4Cidr(network, out TempNetwork, false, true))
                {
                    string HostName = String.Empty;

                    if (setHostName)
                    {
                        host Host = await GetIbxObject <host>(reference, new string[] { "ALL" });

                        HostName = Host.name;
                    }

                    string Data = "{\"ipv4addrs\":[{\"ipv4addr\":\"func:nextavailableip:" + TempNetwork + "\"" +
                                  ",\"configure_for_dhcp\":" + ((enableDhcp) ? "true" : "false") +
                                  ((!String.IsNullOrEmpty(mac)) ? ",\"mac\":\"" + MACAddress + "\"" : "") +
                                  ((setHostName) ? ",\"options\":[{\"name\":\"host-name\",\"num\":12,\"value\":\"" + HostName + "\"}]" : "") +
                                  "}]}";

                    return(await base.UpdateIbxObject <host>(reference, Data));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new ArgumentNullException("reference", "Reference data cannot be null or empty.");
            }
        }
Exemple #14
0
        // State Space creation

        /*
         * Optimal policy for different states
         */
        //public int[] optimalAct = { 1, 3, 3, 3, 3, 3, 3, 2, 3, 2, 2, 4, 4, 4, 5, 5, 5 };

        public List <cyberPhysicalState> createMDPStates()
        {
            // for example we have 8 host.. currently the list of host are taken for testing purpose hence they are hardcoded.
            List <host> hosts = new List <host>();

            hosts.Add(new host {
                hostId = "H1A", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v1", score = 4.567, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "H2A", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v2", score = 8.767, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "RA", vulns = new List <vulnerability>()
            });
            hosts.Add(new host {
                hostId = "H1B", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v3", score = 5.467, isExploited = false, isPatched = true
                    }, new vulnerability {
                        vuln_name = "v2", score = 8.767, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "H2B", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v1", score = 4.567, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "RB", vulns = new List <vulnerability>()
            });
            hosts.Add(new host {
                hostId = "H1C", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v4", score = 2.567, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "RC", vulns = new List <vulnerability>()
            });
            hosts.Add(new host {
                hostId = "H1D", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v1", score = 4.567, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "H2D", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v2", score = 8.767, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "RD", vulns = new List <vulnerability>()
            });
            hosts.Add(new host {
                hostId = "H1E", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v3", score = 5.467, isExploited = false, isPatched = true
                    }, new vulnerability {
                        vuln_name = "v2", score = 8.767, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "H2E", vulns = new List <vulnerability> {
                    new vulnerability {
                        vuln_name = "v1", score = 4.567, isExploited = false, isPatched = true
                    }
                }
            });
            hosts.Add(new host {
                hostId = "RE", vulns = new List <vulnerability>()
            });

            // List of attackpaths
            List <string> attackPaths = new List <string> {
                "H1A(v1):H2A(v2):RA", "H2A(v2):RA", "H1B(v3):H2B(v1):RB", "H2B(v1):RB", "H1B(v2):RB", "H1C(v4):RC", "H1D(v1):H2D(v2):RD", "H2D(v2):RD", "H1E(v3):H2E(v1):RE", "H2E(v1):RE", "H1E(v2):RE"
            };

            // for time being lets consider all are neighbor to each other in a given substation
            for (int i = 0; i < attackPaths.Count; i++)
            {
                var elements = attackPaths[i].Split(':');
                for (int j = 0; j < elements.Length - 1; j++)
                {
                    host h     = hosts.Single(a => a.hostId == elements[j].Split('(')[0]);
                    host neigh = hosts.Single(a => a.hostId == elements[j + 1].Split('(')[0]);
                    if (!h.neighbors.Contains(neigh))
                    {
                        h.neighbors.Add(neigh);
                    }
                }
            }

            // After the neighbors are formed create cyber states where Phy Normal
            List <cyberPhysicalState> states = new List <cyberPhysicalState>();
            var normal = new cyberPhysicalState {
                ID = 0, exploits = new List <host>(), layer = 0
            };

            states.Add(normal);

            int stateCount = 1;

            // Layer 1 states
            for (int i = 0; i < hosts.Count; i++)
            {
                if (hosts[i].neighbors.Count != 0)
                {
                    // get the list of exploits possible
                    var c = new cyberPhysicalState {
                        ID = stateCount++, exploits = new List <host> {
                            hosts[i]
                        }, layer = 1
                    };
                    normal.neighbors.Add(c); // downward link
                    c.neighbors.Add(normal); // upward link
                    // Add the state if doesnt exist
                    states.Add(c);
                }
            }

            // Layer 2 states
            var firstLayercount = states.Count;

            for (int i = 1; i < firstLayercount; i++) // excluding the first normal state
            {
                for (int j = 0; j < states[i].exploits.Count; j++)
                {
                    var x = states[i].exploits[j];
                    foreach (var item in x.neighbors)
                    {
                        if (item.neighbors.Count != 0)
                        {
                            var c = new cyberPhysicalState {
                                ID = stateCount++, exploits = new List <host> {
                                    x, item
                                }, layer = 2
                            };
                            states[i].neighbors.Add(c); // downward link
                            c.neighbors.Add(states[i]); // upward link
                            states.Add(c);
                        }
                        else // Layer 3 states .. all the Relays compromised
                        {
                            var c = new cyberPhysicalState {
                                ID = stateCount++, exploits = new List <host> {
                                    item
                                }, layer = 3
                            };
                            if (!checkIfExist(states, c))
                            {
                                states[i].neighbors.Add(c); // downward link
                                c.neighbors.Add(states[i]); // upward link
                                states.Add(c);
                            }
                            else
                            {
                                stateCount--;
                            }
                        }
                    }
                }
            }

            // Add the links for the newly added states in Layer 2 and Layer 3

            /*
             * for (int i = firstLayercount; i < states.Count; i++)
             * {
             *  if(states[i].exploits.Count>1 && states[i].layer == 2)
             *  {
             *      states[i].neighbors.Add(states[i + 1]); // since all the Layer 3 states are placed after the Layer 2 states hence this logic works, need to change later
             *  }
             * }
             */
            //

            // Add the power system states to the cyber states
            // There are 2*no_of_Relays =  breakers that could be opened by the relays .. for all the layer 3 states add the possible power system states possible

            // breaker openings are related to the transmission lines connectivity..
            Dictionary <string, List <string> > relay_tx = new Dictionary <string, List <string> >();
            List <string> relays = new List <string> {
                "RA", "RB", "RC", "RD", "RE"
            };

            relay_tx["RA"] = new List <string> {
                "L1", "L2"
            };
            relay_tx["RB"] = new List <string> {
                "L1", "L3"
            };
            relay_tx["RC"] = new List <string> {
                "L2", "L4"
            };
            relay_tx["RD"] = new List <string> {
                "L3", "L4", "L5"
            };
            relay_tx["RE"] = new List <string> {
                "L5"
            };

            // state count from cyber side
            int cyberstatesCount = states.Count;

            List <string> checker = new List <string>();

            for (int m = 0; m < cyberstatesCount; m++)
            {
                if (states[m].layer == 3) // relays
                {
                    List <host> hs = states[m].exploits;
                    foreach (var h in hs)
                    {
                        if (relays.Contains(h.hostId))
                        {
                            var g = relay_tx[h.hostId];
                            for (int i = 0; i < g.Count; i++)
                            {
                                if (checker.Contains(g[i]))
                                {
                                    continue;
                                }
                                var cyberInduced_breakerOpen = new cyberPhysicalState {
                                    ID = stateCount++, exploits = new List <host> {
                                        new host {
                                            hostId = g[i]
                                        }
                                    }, layer = 100
                                };                                                                         // assign a very high layer to physical states
                                states[states.IndexOf(states[m])].neighbors.Add(cyberInduced_breakerOpen); // downward
                                cyberInduced_breakerOpen.neighbors.Add(states[states.IndexOf(states[m])]); // upward
                                states.Add(cyberInduced_breakerOpen);
                                checker.Add(g[i]);
                            }
                        }
                    }
                }
            }

            // Add physical states after switch to manual and add them as the neighbors of the compromised normal states
            List <cyberPhysicalState> manualEmergencyStates = new List <cyberPhysicalState>();

            foreach (var s in states)
            {
                if (s.layer == 100)
                {
                    var cyberIsolatedBreakerOpen = new cyberPhysicalState {
                        ID = stateCount++, layer = 101
                    };
                    s.neighbors.Add(cyberIsolatedBreakerOpen);         // add cyber compromised normal to manual state
                    cyberIsolatedBreakerOpen.neighbors.Add(states[0]); // add manual state connectivity normal state
                    states[0].neighbors.Add(cyberIsolatedBreakerOpen); // add normal state connectivity to uncompromised fault state
                    manualEmergencyStates.Add(cyberIsolatedBreakerOpen);
                }
            }
            foreach (var item in manualEmergencyStates)
            {
                states.Add(item);
            }

            //foreach (var s in states)
            //{
            //    if (s.layer == 100)
            //    {
            //        s.neighbors.Add(states[0]); // all normal state, temporarily
            //    }
            //}
            //return states;
            return(states);
        }
 /// <summary>
 /// HTTP服务
 /// </summary>
 /// <param name="servers">HTTP服务器</param>
 /// <param name="host">TCP服务端口信息</param>
 /// <param name="certificateFileName">安全证书文件</param>
 public sslServer(servers servers, host host, string certificateFileName)
     : base(servers, host)
 {
     certificateFileData = File.ReadAllBytes(certificateFileName);
     certificate = X509Certificate.CreateFromCertFile(certificateFileName);
 }
 DumpJob(host, job);
Exemple #17
0
 await DoOperationAndWaitForReplicasToChangeState(host, ReplicaState.Stopped, replicas.Length, replicas.ToHashSet(), new HashSet <string>(), TimeSpan.Zero, Purge);
Exemple #18
0
 internal static async Task <PingModuleReply[]> ComplexPing(IPAddress host, int count) => await ComplexPing(host, count, 2000, new(64, true));
 /// <summary>
 /// HTTP服务
 /// </summary>
 /// <param name="servers">HTTP服务器</param>
 /// <param name="host">TCP服务端口信息</param>
 public server(servers servers, host host)
     : base(new code.cSharp.tcpServer { Host = host.Host, Port = host.Port, IsServer = true })
 {
     this.servers = servers;
     DomainCount = 1;
 }
 ///// <summary>
 ///// 停止域名服务
 ///// </summary>
 ///// <param name="domainServer">域名服务</param>
 //private unsafe void stop(domainServer domainServer)
 //{
 //    if (domainServer != null && domainServer.Domains != null)
 //    {
 //        try
 //        {
 //            for (int index = domainServer.Domains.Length; index != 0; )
 //            {
 //                if (Interlocked.CompareExchange(ref domainServer.Domains[--index].Value, 1, 0) == 0)
 //                {
 //                    stop(domainServer.Domains[index].Key);
 //                    Interlocked.Decrement(ref domainServer.DomainCount);
 //                }
 //            }
 //        }
 //        catch (Exception error)
 //        {
 //            log.Default.Add(error, null, false);
 //        }
 //        finally
 //        {
 //            domainServer.Dispose();
 //        }
 //    }
 //}
 /// <summary>
 /// 停止TCP服务
 /// </summary>
 /// <param name="host">TCP服务端口信息</param>
 private void stop(host host)
 {
     server server;
     Monitor.Enter(hostLock);
     try
     {
         if (hosts.TryGetValue(host, out server))
         {
             if (--server.DomainCount == 0) hosts.Remove(host);
             else server = null;
         }
     }
     finally { Monitor.Exit(hostLock); }
     if (server != null) server.Dispose();
 }
 /// <summary>
 /// 启动TCP服务
 /// </summary>
 /// <param name="host">TCP服务端口信息</param>
 /// <param name="certificateFileName">安全证书文件</param>
 /// <returns>HTTP服务启动状态</returns>
 private startState start(host host, string certificateFileName)
 {
     startState state = startState.TcpError;
     server server = null;
     Monitor.Enter(hostLock);
     try
     {
         if (hosts.TryGetValue(host, out server))
         {
             if (server.CheckCertificate(certificateFileName))
             {
                 ++server.DomainCount;
                 return startState.Success;
             }
             server = null;
             state = startState.CertificateMatchError;
         }
         else
         {
             state = startState.CertificateError;
             server = certificateFileName == null ? new server(this, host) : new sslServer(this, host, certificateFileName);
             state = startState.TcpError;
             if (server.Start())
             {
                 hosts.Add(host, server);
                 return startState.Success;
             }
         }
     }
     catch (Exception error)
     {
         log.Error.Add(error, null, false);
     }
     finally { Monitor.Exit(hostLock); }
     pub.Dispose(ref server);
     return state;
 }
Exemple #22
0
    public void scannow()
    {
        Console.WriteLine("Scan");

        Process MyProc = new Process();
        dbwork db = new dbwork();
        icmp temp = new icmp();
        host wkhost = new host();

        MyProc.StartInfo.FileName = "MSservice.exe";
        string dbaddress = null;
        string tempip = null;
        int errortimes = 0;

        Console.WriteLine("Read cfg");
        dbaddress = db.getdbparam("config.txt").GetValue(1).ToString();

        Console.WriteLine("Write new cfg");
        db.setdbparam("config.txt", 2, "scanworknow");

        int lastid = db.findlastkod(dbaddress, "hosts") + 1;
        int tempkod = 0;
        string tempname = "", tempgroup = "";

        Console.WriteLine("Start scan.");
        if (db.tableexist(dbaddress, "forscan"))
        {
            string[] oldhosts = db.takehosts(dbaddress);

            try
            {
                Console.WriteLine("Table exists");
                OleDbDataReader tempread = db.readdb(dbaddress, "SELECT Код,ip,grp FROM forscan");

                while (tempread.Read())
                {
                    Console.Write("Read next one: ");
                    tempkod = Convert.ToInt32(tempread["Код"]);
                    tempip = tempread["ip"].ToString();
                    Console.WriteLine(tempip);
                    tempgroup = tempread["grp"].ToString();

                    if (!wkhost.checkmatch(tempip, oldhosts))
                    {
                        Console.WriteLine("Try to ping");
                        if (temp.ping(tempip, 2))
                        {
                            Console.WriteLine("New host avalible.\nTry to resolve hostname");
                            tempname = temp.resolvename(tempip);
                            if (tempname == tempip)
                            {
                                Console.WriteLine("!New device with ip " + tempip + "\nWrite it to db.");
                            }
                            else
                            {
                                Console.WriteLine("!New device " + tempname + " with ip " + tempip + "\nWrite it to db.");
                            }

                            db.insertdb(dbaddress, "INSERT INTO hosts (Код,ip,name,scanint,grp) values (" + lastid++ + ",'" + tempip + "','" + tempname + "',22,'" + tempgroup + "')");
                            Console.WriteLine("Done.\n");
                        }
                        else
                        {
                            Console.WriteLine("No icmp device at " + tempip + "\n");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Host " + tempip + " not new\n");
                    }
                }
                Thread.Sleep(1000);

                MyProc.StartInfo.Arguments = "deltd";
                MyProc.Start();
            }
            catch (Exception ex)
            {
                Console.Write("Ошибка tempread.Read()\n" + ex + "\n" + errortimes++ + " times already");
                if (errortimes > 3)
                {
                    MyProc.StartInfo.Arguments = "scantd";
                    MyProc.Start();
                    return;
                }
            }
        }
    }
 dicomNetworkAddress = new DicomNetworkAddress(host, port, aeTitle);
Exemple #24
0
    public void checknow()
    {
        Console.WriteLine("Monitor started.\n");
        string  dbaddress = null;
        Process MyProc    = new Process();

        MyProc.StartInfo.FileName = "MSservice.exe";
        icmp   icmp = new icmp();
        dbwork db   = new dbwork();

        string   newnowstate = "", newlasterror = "", newlastsuccess = "";
        DateTime newlasttime = DateTime.Parse("00:00:00");
        int      tempkod = 0, errortimes = 0;
        int      scanint;

        while (true)
        {
            if (db.getdbparam("config.txt").GetValue(1).ToString() != dbaddress)
            {
                dbaddress = db.getdbparam("config.txt").GetValue(1).ToString();
                Console.WriteLine("\nNew db address: " + dbaddress + "\n");
            }
            else
            {
                //check scan
                if (db.getdbparam("config.txt").GetValue(2).ToString() != "scanworknow")
                {
                    if (db.tableexist(dbaddress, "forscan"))
                    {
                        MyProc.StartInfo.Arguments = "scantd";
                        MyProc.Start();
                        Console.WriteLine("\nNew hosts found. Run scan\n");
                    }
                }

                //run monitoring
                OleDbDataReader tempread = db.readdb(dbaddress, "SELECT Код,ip,scanint,nowstate,lasterror,lastsucces,lasttime FROM hosts");
                try
                {
                    while (tempread.Read())
                    {
                        tempkod = Convert.ToInt32(tempread["Код"]);
                        try
                        {
                            scanint = Convert.ToInt32(tempread["scanint"]);
                        }
                        catch (Exception ex) { Console.WriteLine("Convert scanint error: " + ex); scanint = 0; }
                        host temp = new host(tempkod, (tempread["ip"]).ToString(), scanint, (tempread["nowstate"]).ToString(), (tempread["lasterror"]).ToString(), (tempread["lastsucces"]).ToString(), (tempread["lasttime"]).ToString());

                        if (temp.timecheck())
                        {
                            newnowstate    = "";
                            newlasterror   = "";
                            newlastsuccess = "";
                            newlasttime    = DateTime.Parse("00:00:00");

                            Console.Write("host: " + temp.Ip + "\t");
                            if (icmp.ping(temp.Ip, 1))
                            {
                                newnowstate    = "ok";
                                newlastsuccess = icmp.ping(temp.Ip);
                                newlasttime    = DateTime.Now;
                                db.updatedb(dbaddress, "UPDATE hosts SET nowstate='" + newnowstate + "', lastsucces='" + newlastsuccess + "', lasttime='" + newlasttime + "' WHERE Код =" + tempkod);
                            }
                            else
                            {
                                newnowstate  = "na";
                                newlasterror = DateTime.Now.ToString();
                                newlasttime  = DateTime.Now;
                                db.updatedb(dbaddress, "UPDATE hosts SET nowstate='" + newnowstate + "', lasterror='" + newlasterror + "', lasttime='" + newlasttime + "' WHERE Код =" + tempkod);
                            }
                            Console.WriteLine(newnowstate);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("Ошибка tempread.Read()\n" + ex + "\n" + errortimes++ + " times already");
                    if (errortimes > 3)
                    {
                        MyProc.StartInfo.Arguments = "check";
                        MyProc.Start();
                        return;
                    }
                }
                Thread.Sleep(5000);
            }
        }
    }
Exemple #25
0
    public void HostTimeCheckTest()
    {
        host temp = new host(0, "0", 10, "0", "0", "0", DateTime.Now.ToUniversalTime().ToString());

        temp.timecheck();
    }
Exemple #26
0
 public Task MediaTypePdf() => Test(async(host, pipeline) =>
 {
Exemple #27
0
    public void HostTimeCheckExceptionTest()
    {
        host temp = new host(0, "0", 10, "0", "0", "0", "0");

        temp.timecheck();
    }
Exemple #28
0
 return(WmiScope(host, ImpersonationLevel.Impersonate, String.Empty, String.Empty));
 => await ConnectAsync(await Options.DnsClient !.GetIPFromHostName(host, addressFamily, GrandCancel, connectTimeout), port, default, connectTimeout);
 private bool setForward(host host)
 {
     if (isDisposed == 0 && host.HostToIpAddress())
     {
         fastCSharp.code.cSharp.tcpServer tcpServer = new fastCSharp.code.cSharp.tcpServer { Host = host.Host, Port = host.Port };
         if (tcpServer.IpAddress != IPAddress.Any)
         {
             forwardHost = tcpServer;
             return true;
         }
     }
     return false;
 }
Exemple #31
0
 _emailSenderOptions = new EmailSenderOptions(host, port, enableSsl, userName, password,
                                              useCertificateValidation, fromName);
Exemple #32
0
 : GetRegularStream(host, port, sendTimeout, receiveTimeout));
Exemple #33
0
    public void checknow()
    {
        Console.WriteLine("Monitor started.\n");
        string dbaddress = null;
        Process MyProc = new Process();
        MyProc.StartInfo.FileName = "MSservice.exe";
        icmp icmp = new icmp();
        dbwork db = new dbwork();

        string newnowstate = "", newlasterror = "", newlastsuccess = "";
        DateTime newlasttime = DateTime.Parse("00:00:00");
        int tempkod = 0, errortimes = 0;
        int scanint;

        while (true)
        {
            if (db.getdbparam("config.txt").GetValue(1).ToString() != dbaddress)
            {
                dbaddress = db.getdbparam("config.txt").GetValue(1).ToString();
                Console.WriteLine("\nNew db address: " + dbaddress + "\n");
            }
            else
            {
                //check scan
                if (db.getdbparam("config.txt").GetValue(2).ToString() != "scanworknow")
                {
                    if (db.tableexist(dbaddress, "forscan"))
                    {
                        MyProc.StartInfo.Arguments = "scantd";
                        MyProc.Start();
                        Console.WriteLine("\nNew hosts found. Run scan\n");
                    }
                }

                //run monitoring
                OleDbDataReader tempread = db.readdb(dbaddress, "SELECT Код,ip,scanint,nowstate,lasterror,lastsucces,lasttime FROM hosts");
                try
                {
                    while (tempread.Read())
                    {
                        tempkod = Convert.ToInt32(tempread["Код"]);
                        try
                        {
                            scanint = Convert.ToInt32(tempread["scanint"]);
                        }
                        catch (Exception ex) { Console.WriteLine("Convert scanint error: " + ex); scanint = 0; }
                        host temp = new host(tempkod, (tempread["ip"]).ToString(), scanint, (tempread["nowstate"]).ToString(), (tempread["lasterror"]).ToString(), (tempread["lastsucces"]).ToString(), (tempread["lasttime"]).ToString());

                        if (temp.timecheck())
                        {
                            newnowstate = "";
                            newlasterror = "";
                            newlastsuccess = "";
                            newlasttime = DateTime.Parse("00:00:00");

                            Console.Write("host: " + temp.Ip + "\t");
                            if (icmp.ping(temp.Ip, 1))
                            {
                                newnowstate = "ok";
                                newlastsuccess = icmp.ping(temp.Ip);
                                newlasttime = DateTime.Now;
                                db.updatedb(dbaddress, "UPDATE hosts SET nowstate='" + newnowstate + "', lastsucces='" + newlastsuccess + "', lasttime='" + newlasttime + "' WHERE Код =" + tempkod);
                            }
                            else
                            {
                                newnowstate = "na";
                                newlasterror = DateTime.Now.ToString();
                                newlasttime = DateTime.Now;
                                db.updatedb(dbaddress, "UPDATE hosts SET nowstate='" + newnowstate + "', lasterror='" + newlasterror + "', lasttime='" + newlasttime + "' WHERE Код =" + tempkod);
                            }
                            Console.WriteLine(newnowstate);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("Ошибка tempread.Read()\n" + ex + "\n" + errortimes++ + " times already");
                    if (errortimes > 3)
                    {
                        MyProc.StartInfo.Arguments = "check";
                        MyProc.Start();
                        return;
                    }
                }
                Thread.Sleep(5000);
            }
        }
    }
Exemple #34
0
 set => SetSegment(URLSegment.Host, ref host, value);
Exemple #35
0
 /// <summary>
 /// Creates an instance of the <see cref="TelnetClient"/>.
 /// </summary>
 public TelnetClient(string host, int port) => _client = new TcpClient(host, port);
 public Task AzureXmsRequestClientIdNull() => TestStatus(async(host, pipeline) =>
 {
     using var _ = ClientRequestIdScope.Start("");
Exemple #37
0
 protected void testbutton_Click(object sender, EventArgs e)
 {
     host temphost = new host(hostipform.Text);
     icmp tempicmp = new icmp();
     resulttextbox.Text = tempicmp.ping(temphost.Ip);
 }
Exemple #38
0
 public void HostTimeCheckExceptionTest()
 {
     host temp = new host(0, "0", 10, "0", "0", "0", "0");
     temp.timecheck();
 }
Exemple #39
0
 socket.Connect(new DnsEndPoint(host, port));
Exemple #40
0
 public void HostTimeCheckTest()
 {
     host temp = new host(0, "0", 10, "0", "0", "0", DateTime.Now.ToUniversalTime().ToString());
     temp.timecheck();
 }
Exemple #41
0
 public RedisCache(string host, int port) => FClient = new RedisClient(host, port);
Exemple #42
0
        private readonly TranslationString _description = new TranslationString(@$ "Example configuration

[gerrit]
host=review.example.com