Esempio n. 1
0
 private void checkfile()
 {
     newdbaddress = addressbox.Text;
     if ((dbaddress.Equals((Request.PhysicalApplicationPath).ToString() + "App_Data\\" + newdbaddress)) & (temp.tableexist((Request.PhysicalApplicationPath).ToString() + "App_Data\\" + newdbaddress, "hosts")))
     {
         Button2.Visible = false;
         Response.Redirect("monitoring.aspx");
     }
     else
     {
         if (newdbaddress.Contains("accdb"))
         {
             if (temp.tableexist((Request.PhysicalApplicationPath).ToString() + "App_Data\\" + newdbaddress, "hosts"))
             {
                 temp.setdbparam(((Request.PhysicalApplicationPath).ToString() + "App_Data\\config.txt"), 1, newdbaddress);
                 temp.setdbparam(((Request.PhysicalApplicationPath).ToString() + "App_Data\\config.txt"), 2, "scanstopnow");
                 Button2.Visible = false;
                 Response.Redirect("monitoring.aspx");
             }
             else
             {
                 if (CultureInfo.CurrentCulture.DisplayName.Contains("English"))
                 {
                     Label2.Text = "DB error. No 'hosts' table here";
                 }
                 else
                 {
                     Label2.Text = "Ошибка базы данных. Таблица 'hosts' не найдена";
                 }
                 Button2.Visible = true;
             }
         }
         else
         {
             if (CultureInfo.CurrentCulture.DisplayName.Contains("English"))
             {
                 Label2.Text = "Wrong db name";
             }
             else
             {
                 Label2.Text = "Неверное имя базы данных";
             }
         }
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello.");

            monitor m1 = new monitor();
            scan s1 = new scan();
            dbwork db = new dbwork();
            string dbaddress=null;

            try { dbaddress = db.getdbparam("config.txt").GetValue(1).ToString(); }
            catch (System.IO.FileNotFoundException) { Console.WriteLine("Config file is not found"); Console.ReadKey(); return; }

            try
            {
                db.tableexist(dbaddress, "hosts");
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("You have no AccessDatabaseEngine. Contact your administrator.");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Database file at "+dbaddress+"\n");

            if (args.Length == 0)
            {
                m1.checknow();
            }
            else
            {
                if (args[0] == "scantd")
                {
                     s1.scannow(); return;
                }
                if (args[0] == "deltd")
                {
                    Console.WriteLine("Now table forscan delete");
                    try
                    {
                        db.droptdforscandb(dbaddress, "forscan");
                    }
                    catch (System.Data.OleDb.OleDbException) { Console.WriteLine("Can not delete"); return; }
                    Console.WriteLine("Complite.\nWrite new cfg");
                    db.setdbparam("config.txt", 2, "scanstopnow");
                    Console.WriteLine("Done\nGood bye.");
                    Thread.Sleep(3000);
                    return;
                }
                if (args[0] == "check")
                {
                    m1.checknow(); return;
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello.");

            monitor m1        = new monitor();
            scan    s1        = new scan();
            dbwork  db        = new dbwork();
            string  dbaddress = null;

            try { dbaddress = db.getdbparam("config.txt").GetValue(1).ToString(); }
            catch (System.IO.FileNotFoundException) { Console.WriteLine("Config file is not found"); Console.ReadKey(); return; }

            try
            {
                db.tableexist(dbaddress, "hosts");
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("You have no AccessDatabaseEngine. Contact your administrator.");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Database file at " + dbaddress + "\n");

            if (args.Length == 0)
            {
                m1.checknow();
            }
            else
            {
                if (args[0] == "scantd")
                {
                    s1.scannow(); return;
                }
                if (args[0] == "deltd")
                {
                    Console.WriteLine("Now table forscan delete");
                    try
                    {
                        db.droptdforscandb(dbaddress, "forscan");
                    }
                    catch (System.Data.OleDb.OleDbException) { Console.WriteLine("Can not delete"); return; }
                    Console.WriteLine("Complite.\nWrite new cfg");
                    db.setdbparam("config.txt", 2, "scanstopnow");
                    Console.WriteLine("Done\nGood bye.");
                    Thread.Sleep(3000);
                    return;
                }
                if (args[0] == "check")
                {
                    m1.checknow(); return;
                }
            }
        }
Esempio n. 4
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;
                }
            }
        }
    }
Esempio n. 5
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;
                }
            }
        }
    }